1、返回头部的滑动动画
JQuery.fn.scrollTo = function(speed){
var targetOffset = $(this).offset().top;
$("html.body").stop().animate({scrollTop:targetOffset},speed);
return this;
}
//使用
$("#goheader").click(function(){
$("body").scrollTo(500);
return false;
});
2、获取鼠标的位置
$(document).ready(function(){
$(document).mousemove(function(e){
$('#XY').html("X: " + e.pageX + " | Y : " + e.pageY);
});
});
3、点击div的跳转
<div><a href="index.html">home</a></div>
$('div').click(function(){
window.location = $(this).find("a").attr("href");
return false;
});
4、设置div在屏幕中央
$(document).ready(function(){
jQuery.fn.center = function(){
this.css("position","absolute");
this.css("top",($(window).height() - this.height())/2 + $(window).scrollTop() + "px");
this.css("left",($(window).width() - this.width())/2 + $(window).scrollLeft() + "px");
}
});
$("#XY").center(); //使用
JQuery.fn.scrollTo = function(speed){
var targetOffset = $(this).offset().top;
$("html.body").stop().animate({scrollTop:targetOffset},speed);
return this;
}
//使用
$("#goheader").click(function(){
$("body").scrollTo(500);
return false;
});
2、获取鼠标的位置
$(document).ready(function(){
$(document).mousemove(function(e){
$('#XY').html("X: " + e.pageX + " | Y : " + e.pageY);
});
});
3、点击div的跳转
<div><a href="index.html">home</a></div>
$('div').click(function(){
window.location = $(this).find("a").attr("href");
return false;
});
4、设置div在屏幕中央
$(document).ready(function(){
jQuery.fn.center = function(){
this.css("position","absolute");
this.css("top",($(window).height() - this.height())/2 + $(window).scrollTop() + "px");
this.css("left",($(window).width() - this.width())/2 + $(window).scrollLeft() + "px");
}
});
$("#XY").center(); //使用