A couple useful jQuery Snippets

August 9, 2009
By SeanJA

For popups, just add class=”popup”

jQuery('a.popup').live('click', function(){
	newwindow=window.open($(this).attr('href'),'','height=200,width=150');
	if (window.focus) {newwindow.focus()}
	return false;
});

To open in a new tab, add class=”newTab”

jQuery('a.newTab').live('click', function(){
	newwindow=window.open($(this).href);
	jQuery(this).target = "_blank";
	return false;
});

Check if something is in view

function in_view(elem){
	var docViewTop = jQuery(window).scrollTop();
	var docViewBottom = docViewTop + jQuery(window).height();
 
	var elemTop = jQuery(elem).offset().top;
	var elemBottom = elemTop + jQuery(elem).height();
 
	return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom) && (elemBottom <= docViewBottom) &&  (elemTop >= docViewTop));
}
Share and Enjoy:
  • Twitter
  • DZone
  • del.icio.us
  • Slashdot
  • Digg
  • Reddit
  • HackerNews
  • Technorati
  • Google Bookmarks
  • RSS
  • StumbleUpon
  • Yahoo! Buzz
  • LinkedIn
  • Facebook
  • Print
  • PDF
  • email

Related posts:

  1. Using the jQuery-UI Autocomplete Widget
  2. JQuery and WordPress
  3. Documenting PHP Code
  4. A better way to use jQuery in WordPress Themes
  5. jQuery bsod plugin

9 Responses to A couple useful jQuery Snippets

  1. [...] Source This entry was written by admin, posted on 06/07/2010 at 5:45 AM, filed under jQuery. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL. « Validate a date of birth using jQuery [...]

  2. SM on March 3, 2010 at 4:24 am

    Nice snippets! Thanks

  3. designfolio: on February 27, 2010 at 10:01 pm

    [...] Source [...]

  4. [...] » Source [...]

  5. [...] » Source [...]

  6. [...] –> source [...]

  7. 10 jQuery snippets for efficient developers on December 14, 2009 at 11:09 am

    [...] » Source [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*