您的位置:首页 > Web前端 > JQuery

jquery 返回顶部、图片比例缩小、验证元素是否存在

2013-09-05 20:23 351 查看
jquery 返回顶部、图片比例缩小、验证元素是否存在
返回顶部代码
$(document).ready(function() {
$('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 }, 900);
return false;
}
}
});
});
图片比例缩小
代码如下:

$(document).ready(function(){
var ywidth = 450;//初始最大宽度
$(”img”).each(function(){
if($(this).width() > ywidth) {
$(this).width(ywidth);
$(this).mouseo教程ver(function(){
$(this).css教程(”cursor”,”hand”);
});
$(this).click(function(){
window.location.href = $(this).attr(”src”);
});
}
});
});jquery 验证元素是否存在

$(document).ready(function() {
if ($('#id').length) {
// do something
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: