Send this to a friend
1
2 $('a[href*=#]').click(function() {
3
4 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
5
6 var $target = $(this.hash);
7
8 $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
9
10 if ($target.length) {
11 var targetOffset = $target.offset().top;
12 $('html,body').animate({scrollTop: targetOffset}, 1000);
13 return false;
14 }
15 }
16 });
$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
if ($target.length) {
var targetOffset = $target.offset().top;
$('html,body').animate({scrollTop: targetOffset}, 1000);
return false;
}
}
});
Send this to a friend
1 $('a.popup').live('click', function(){
2 newwindow=window.open($(this).attr('href'),'','height=200,width=150');
3 if (window.focus) {newwindow.focus()}
4 return false;
5 });
$('a.popup').live('click', function(){
newwindow=window.open($(this).attr('href'),'','height=200,width=150');
if (window.focus) {newwindow.focus()}
return false;
});
Send this to a friend
http://docs.jQuery.com/DOM/Traversing/Selectors
1 $('h1')
2 $('#meuID')
3 $('.minhaClasse')
4 $('[width]')
5 $('[width=500]')
6 $('img[width=300]')
7 $('img[src$=png]')
8 $('a[href^=http://localhost]')
9 $('a[href$=pdf]')
10 $('a[href*=www]')
11 $(':empty')
12 $('div:empty')
13 $(':has(p)')
14 $('div:has(a)');
15 $("p:contains('dinei')")
16 $("p:eq(0)")
$('h1')
$('#meuID')
$('.minhaClasse')
$('[width]')
$('[width=500]')
$('img[width=300]')
$('img[src$=png]')
$('a[href^=http://localhost]')
$('a[href$=pdf]')
$('a[href*=www]')
$(':empty')
$('div:empty')
$(':has(p)')
$('div:has(a)');
$("p:contains('dinei')")
$("p:eq(0)")
Send this to a friend
1 <a href="#top" onclick="$('html, body').animate({scrollTop:0}, 'slow'); return false;">top</a>
<a href="#top" onclick="$('html, body').animate({scrollTop:0}, 'slow'); return false;">top</a>
Send this to a friend
1 $(document).ready(function() {
2 $('dd').toggle();
3 $('dt').click(function() {$(this).next('dd').toggle('slideDown');});
4 });
$(document).ready(function() {
$('dd').toggle();
$('dt').click(function() {$(this).next('dd').toggle('slideDown');});
});
Send this to a friend
1
2 $(document).ready(function(){
3 if(jQuery.browser.msie && jQuery.browser.version<7){
4 $('[class*="bla"]').hover(
5 function () {
6 $(this).addClass('hover');
7 },
8 function () {
9 $(this).removeClass('hover');
10 }
11 );
12 }
13 });
$(document).ready(function(){
if(jQuery.browser.msie && jQuery.browser.version<7){
$('[class*="bla"]').hover(
function () {
$(this).addClass('hover');
},
function () {
$(this).removeClass('hover');
}
);
}
});
Send this to a friend
http://www.seodenver.com/simple-vertical-align-plugin-for-jquery/
1 (function ($) {
2
3 $.fn.vAlign = function() {
4 return this.each(function(i){
5 var ah = $(this).height();
6 var ph = $(this).parent().height();
7 var mh = (ph - ah) / 2;
8 $(this).css('margin-top', mh);
9 });
10 };
11 })(jQuery);
12
13
(function ($) {
$.fn.vAlign = function() {
return this.each(function(i){
var ah = $(this).height();
var ph = $(this).parent().height();
var mh = (ph - ah) / 2;
$(this).css('margin-top', mh);
});
};
})(jQuery);
Send this to a friend
from: http://www.position-absolute.com/articles/jquery-fade-and-slide-toggle-plugin/
1 jQuery.fn.fadeSliderToggle = function(settings) {
2 settings = jQuery.extend({
3 speed:500,
4 easing : "swing"
5 }, settings)
6
7 caller = this
8 if($(caller).css("display") == "none"){
9 $(caller).animate({
10 opacity: 1,
11 height: 'toggle'
12 }, settings.speed, settings.easing);
13 }else{
14 $(caller).animate({
15 opacity: 0,
16 height: 'toggle'
17 }, settings.speed, settings.easing);
18 }
19 };
20
21
jQuery.fn.fadeSliderToggle = function(settings) {
settings = jQuery.extend({
speed:500,
easing : "swing"
}, settings)
caller = this
if($(caller).css("display") == "none"){
$(caller).animate({
opacity: 1,
height: 'toggle'
}, settings.speed, settings.easing);
}else{
$(caller).animate({
opacity: 0,
height: 'toggle'
}, settings.speed, settings.easing);
}
};
Send this to a friend
1 $(document).ready(function() { jQuery.fn.each( function(i) { console.log(i); }); });
$(document).ready(function() { jQuery.fn.each( function(i) { console.log(i); }); });
Send this to a friend
http://ralphwhitbeck.com/content/binary/twitter-json-jquery.html
1 <html>
2 <head>
3 <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
4 <script>
5 $(document).ready( function() {
6
7 var url = "http://twitter.com/status/user_timeline/RedWolves.json?count=3&callback=?";
8 $.getJSON(url,
9 function(data){
10 $.each(data, function(i, item) {
11 $("img#profile").attr("src", item.user["profile_image_url"]);
12 $("#tweets ul").append("<li>" + item.text.linkify() + " <span class='created_at'>" + relative_time(item.created_at) + " via " + item.source + "</span></li>");
13 });
14 });
15 });
16
17 String.prototype.linkify = function() {
18 return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
19 return m.link(m);
20 });
21 };
22 function relative_time(time_value) {
23 var values = time_value.split(" ");
24 time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
25 var parsed_date = Date.parse(time_value);
26 var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
27 var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
28 delta = delta + (relative_to.getTimezoneOffset() * 60);
29
30 var r = '';
31 if (delta < 60) {
32 r = 'a minute ago';
33 } else if(delta < 120) {
34 r = 'couple of minutes ago';
35 } else if(delta < (45*60)) {
36 r = (parseInt(delta / 60)).toString() + ' minutes ago';
37 } else if(delta < (90*60)) {
38 r = 'an hour ago';
39 } else if(delta < (24*60*60)) {
40 r = '' + (parseInt(delta / 3600)).toString() + ' hours ago';
41 } else if(delta < (48*60*60)) {
42 r = '1 day ago';
43 } else {
44 r = (parseInt(delta / 86400)).toString() + ' days ago';
45 }
46
47 return r;
48 }
49 function twitter_callback ()
50 {
51 return true;
52 }
53
54 </script>
55 </head>
56 <body>
57 <div id="tweets">
58 <img id="profile">
59 <ul></ul>
60 </div>
61 </body>
62 </html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script>
$(document).ready( function() {
var url = "http://twitter.com/status/user_timeline/RedWolves.json?count=3&callback=?";
$.getJSON(url,
function(data){
$.each(data, function(i, item) {
$("img#profile").attr("src", item.user["profile_image_url"]);
$("#tweets ul").append("<li>" + item.text.linkify() + " <span class='created_at'>" + relative_time(item.created_at) + " via " + item.source + "</span></li>");
});
});
});
String.prototype.linkify = function() {
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
return m.link(m);
});
};
function relative_time(time_value) {
var values = time_value.split(" ");
time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
var parsed_date = Date.parse(time_value);
var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
delta = delta + (relative_to.getTimezoneOffset() * 60);
var r = '';
if (delta < 60) {
r = 'a minute ago';
} else if(delta < 120) {
r = 'couple of minutes ago';
} else if(delta < (45*60)) {
r = (parseInt(delta / 60)).toString() + ' minutes ago';
} else if(delta < (90*60)) {
r = 'an hour ago';
} else if(delta < (24*60*60)) {
r = '' + (parseInt(delta / 3600)).toString() + ' hours ago';
} else if(delta < (48*60*60)) {
r = '1 day ago';
} else {
r = (parseInt(delta / 86400)).toString() + ' days ago';
}
return r;
}
function twitter_callback ()
{
return true;
}
</script>
</head>
<body>
<div id="tweets">
<img id="profile">
<ul></ul>
</div>
</body>
</html>