you are in: codestackercodes [RSS] → tag: jquery [RSS]

background animation Delicious Email

requires jquery.ui or jquery.color (https://github.com/jquery/jquery-color)

show/hide lines
   1  $.fn.backgroundAnimation : function(bgcolor, fgcolor, duration) {
   2  	$(this).animate({ backgroundColor: bgcolor }, duration).css('color', fgcolor);
   3  }
created by leozera — 31 July 2011 — get a short url — tags: jquery embed

highlight an element Delicious Email

requires jquery.ui or jquery.color (https://github.com/jquery/jquery-color)

show/hide lines
   1  $.fn.highlight : function (highlightColor, duration) {
   2      var highlightBg = highlightColor || "#FFFF9C";
   3      var animateMs = duration || 2000;
   4      var originalBg = this.css("background-color");
   5  
   6      if (!originalBg || originalBg == highlightBg)
   7          originalBg = "#FFFFFF"; // default to white
   8  
   9      $(this).css("backgroundColor", highlightBg).animate({ backgroundColor: originalBg }, animateMs, null, function () { $(this).css("backgroundColor", originalBg);  });
  10  }
created by leozera — 31 July 2011 — get a short url — tags: jquery embed

center vertically element Delicious Email

show/hide lines
   1  $.fn.center = function (relation) {
   2      var center_in = (relation) ? $(relation) : $(window);
   3      
   4      this.css("position","absolute");
   5      this.css("top", ( center_in.height() - this.height() ) / 2+center_in.scrollTop() + "px");
   6      this.css("left", ( center_in.width() - this.width() ) / 2+center_in.scrollLeft() + "px");
   7      return this;
   8  };
created by leozera — 31 July 2011 — get a short url — tags: jquery embed

add to bookmarks using jquery Delicious Email

show/hide lines
   1  $("a#bookmark").click(function(){
   2     var bookmarkUrl = this.href;
   3     var bookmarkTitle = this.title;
   4  	 
   5     if ($.browser.mozilla) // For Mozilla Firefox Bookmark
   6     { 
   7  	window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
   8     } 
   9     else if($.browser.msie || $.browser.webkit) // For IE Favorite
  10     { 
  11  	window.external.AddFavorite( bookmarkUrl, bookmarkTitle); 
  12     }
  13     else if($.browser.opera ) // For Opera Browsers
  14     { 
  15  	$(this).attr("href",bookmarkUrl);
  16  	$(this).attr("title",bookmarkTitle);
  17  	$(this).attr("rel","sidebar");
  18  	$(this).click();
  19     } 
  20     else // for other browsers which does not support
  21     { 
  22          alert('Please hold CTRL+D and click the link to bookmark it in your browser.');
  23     }
  24     return false; 
  25  });
created by leozera — 17 July 2011 — get a short url — tags: jquery embed

detecting ie version with jquery Delicious Email

show/hide lines
   1  var IE = $.browser.msie, IEv = $.browser.version;
   2  
   3  if (IE) { //could be improved
   4      var IE6 = parseInt(IEv) == 6,
   5          IE7 = parseInt(IEv) == 7, 
   6          IE8 = parseInt(IEv) == 8, 
   7          IE9 = parseInt(IEv) == 9;
   8  }
   9  
  10  //Usage:
  11  
  12  if (IE) {
  13      //Do something for all IE versions
  14  }
  15  if (IE7) {
  16      //Do stuff just for IE7
  17  }
  18  if (IE7 || IE8) {
  19      //Do stuff just for IE7 or IE8
  20  }
  21  if (!IE6) {
  22      //Do something if not IE6
  23  }
created by leozera — 11 July 2011 — get a short url — tags: browser ie jquery embed

simple jquery table sort Delicious Email

requires jquery.sortElements.js (https://github.com/jamespadolsey/jQuery-Plugins/blob/master/sortElements/jquery.sortElements.js)

via http://stackoverflow.com/questions/3160277/jquery-table-sort

show/hide lines
   1  var table = $('table');
   2  
   3  $('th').wrapInner('<span title="Sort this column"/>').each(function(){
   4       var th = $(this), thIndex = th.index(), inverse = false;
   5       th.click(function(){
   6           table.find('td').filter(function(){
   7               return $(this).index() === thIndex;
   8           }).sortElements(function(a, b){
   9               return $.text([a]) > $.text([b]) ?
  10                   inverse ? -1 : 1
  11                   : inverse ? 1 : -1;
  12           }, function(){
  13  			return this.parentNode; 
  14           });
  15           inverse = !inverse;
  16       });
  17  });
created by leozera — 01 July 2011 — get a short url — tags: jquery table embed

smooth scrolling Delicious Email

http://snipplr.com/view.php?codeview&id=53669

show/hide lines
   1  $(document).ready(function() {
   2    function filterPath(string) {
   3    return string
   4      .replace(/^\//,'')
   5      .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
   6      .replace(/\/$/,'');
   7    }
   8    var locationPath = filterPath(location.pathname);
   9    var scrollElem = scrollableElement('html', 'body');
  10  
  11    $('a[href*=#]').each(function() {
  12      var thisPath = filterPath(this.pathname) || locationPath;
  13      if (  locationPath == thisPath
  14      && (location.hostname == this.hostname || !this.hostname)
  15      && this.hash.replace(/#/,'') ) {
  16        var $target = $(this.hash), target = this.hash;
  17        if (target) {
  18          var targetOffset = $target.offset().top;
  19          $(this).click(function(event) {
  20            event.preventDefault();
  21            $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
  22              location.hash = target;
  23            });
  24          });
  25        }
  26      }
  27    });
  28  
  29    // use the first element that is "scrollable"
  30    function scrollableElement(els) {
  31      for (var i = 0, argLength = arguments.length; i <argLength; i++) {
  32        var el = arguments[i],
  33            $scrollElement = $(el);
  34        if ($scrollElement.scrollTop()> 0) {
  35          return el;
  36        } else {
  37          $scrollElement.scrollTop(1);
  38          var isScrollable = $scrollElement.scrollTop()> 0;
  39          $scrollElement.scrollTop(0);
  40          if (isScrollable) {
  41            return el;
  42          }
  43        }
  44      }
  45      return [];
  46    }
  47  
  48  });
created by leozera — 23 June 2011 — get a short url — tags: jquery embed

simple jquery scroll to top Delicious Email

show/hide lines
   1  $(document).ready(function() {
   2  	$('.backtotop').click(function(){
   3  		$('html, body').animate({scrollTop:0}, 'slow');
   4  	});
   5  });
created by leozera — 23 June 2011 — get a short url — tags: jquery embed

placeholder attribute for inputs in IE Delicious Email

require jquery and modernizer

show/hide lines
   1  if(!Modernizr.input.placeholder){
   2  	$("input").each(function(){
   3  		if($(this).val()=="" && $(this).attr("placeholder")!=""){
   4  			$(this).val($(this).attr("placeholder"));
   5  			$(this).focus(function(){
   6  				if($(this).val()==$(this).attr("placeholder")) $(this).val("");
   7  			});
   8  			$(this).blur(function(){
   9  				if($(this).val()=="") $(this).val($(this).attr("placeholder"));
  10  			});
  11  		}
  12  	});
  13  }
created by leozera — 08 March 2011 — get a short url — tags: browser hack ie jquery embed

open all externals links in a new window Delicious Email

show/hide lines
   1  $('a[href*=http:]').each(function(){
   2          if (this.host != window.location.host) {
   3                  $(this).attr('target', '_new');
   4          }
   5  });
created by leozera — 13 February 2011 — get a short url — tags: jquery embed
Displaying records 1 - 10 of 31