javascript 圖片上一張下一張鏈接效果代碼
更新時(shí)間:2010年03月12日 18:49:03 作者:
人人網(wǎng)相冊(cè)和酷狗音樂(lè)網(wǎng)站上面當(dāng)鼠標(biāo)移動(dòng)到圖片上面,鼠標(biāo)的形狀會(huì)根據(jù)其在圖片上的位置改變。
貼個(gè)實(shí)現(xiàn)方法:
代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>無(wú)標(biāo)題頁(yè)</title>
<script src="jquery-1.3.2.js" type="text/javascript"></script>
<style type="text/css">
.rootclass{ border:none;position:relative;}
</style>
<script type="text/javascript">
$(document).ready(function() {
$(".rootclass").mousemove(function(e){
var positionX=e.originalEvent.x||e.originalEvent.layerX||0;
if(positionX<=$(this).width()/2){
this.style.cursor='url("pre.cur"),auto';
$(this).attr('title','點(diǎn)擊查看上一張');
$(this).parent().attr('href',$(this).attr('left'));
}else{
this.style.cursor='url("next.cur"),auto';
$(this).attr('title','點(diǎn)擊查看下一張');
$(this).parent().attr('href',$(this).attr('right'));
}
});
});
</script>
</head>
<body>
<a href="#" >
<img src="11.bmp" alt="" class="rootclass" left="http://www.google.cn" right="http://www.baidu.cn" />
</a>
</body>
</html>
說(shuō)明:1.需要調(diào)用Jquery。
2.這里獲取鼠標(biāo)在圖片的位置用了個(gè)投機(jī)的方法,設(shè)置圖片的position:relative
直接使用 var positionX=e.originalEvent.x||e.originalEvent.layerX||0; 來(lái)獲取。
3. 為了方便直接在圖片上添加left="http://www.google.cn" right="http://www.baidu.cn" 為其上一張,下一張鏈接地址。記得給<img />套上<a href="#" ></a>
在線演示代碼:http://demo.jb51.net/js/img_left_right/jquery_img_lr.htm
打包下載地址 http://www.dbjr.com.cn/jiaoben/25129.html
相關(guān)文章:
clientX,pageX,offsetX,x,layerX,screenX,offsetLef
JS在IE和FireFox之間常用函數(shù)的區(qū)別小結(jié)
javascript offsetX與layerX區(qū)別
jQuery 點(diǎn)擊圖片跳轉(zhuǎn)上一張或下一張功能的實(shí)現(xiàn)代碼
代碼
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>無(wú)標(biāo)題頁(yè)</title>
<script src="jquery-1.3.2.js" type="text/javascript"></script>
<style type="text/css">
.rootclass{ border:none;position:relative;}
</style>
<script type="text/javascript">
$(document).ready(function() {
$(".rootclass").mousemove(function(e){
var positionX=e.originalEvent.x||e.originalEvent.layerX||0;
if(positionX<=$(this).width()/2){
this.style.cursor='url("pre.cur"),auto';
$(this).attr('title','點(diǎn)擊查看上一張');
$(this).parent().attr('href',$(this).attr('left'));
}else{
this.style.cursor='url("next.cur"),auto';
$(this).attr('title','點(diǎn)擊查看下一張');
$(this).parent().attr('href',$(this).attr('right'));
}
});
});
</script>
</head>
<body>
<a href="#" >
<img src="11.bmp" alt="" class="rootclass" left="http://www.google.cn" right="http://www.baidu.cn" />
</a>
</body>
</html>
說(shuō)明:1.需要調(diào)用Jquery。
2.這里獲取鼠標(biāo)在圖片的位置用了個(gè)投機(jī)的方法,設(shè)置圖片的position:relative
直接使用 var positionX=e.originalEvent.x||e.originalEvent.layerX||0; 來(lái)獲取。
3. 為了方便直接在圖片上添加left="http://www.google.cn" right="http://www.baidu.cn" 為其上一張,下一張鏈接地址。記得給<img />套上<a href="#" ></a>
在線演示代碼:http://demo.jb51.net/js/img_left_right/jquery_img_lr.htm
打包下載地址 http://www.dbjr.com.cn/jiaoben/25129.html
相關(guān)文章:
clientX,pageX,offsetX,x,layerX,screenX,offsetLef
JS在IE和FireFox之間常用函數(shù)的區(qū)別小結(jié)
javascript offsetX與layerX區(qū)別
jQuery 點(diǎn)擊圖片跳轉(zhuǎn)上一張或下一張功能的實(shí)現(xiàn)代碼
相關(guān)文章
純JS實(shí)現(xiàn)的批量圖片預(yù)覽加載功能
需要一張轉(zhuǎn)圈的小圖片,需要預(yù)覽的所有圖片默認(rèn)的位置全是這張小圖片,滾輪滾到原圖需要出現(xiàn)的位置時(shí)候,預(yù)覽加載替換小圖片2011-08-08javascript 火狐(firefox)不顯示本地圖片問(wèn)題解決
在Firefox一直不能用js做出圖片預(yù)覽的效果,下面這個(gè)即可解決,用替換的方法實(shí)現(xiàn)firefox支持得的路徑格式2008-07-07js與自動(dòng)伸縮圖片 自動(dòng)縮小圖片的多瀏覽器兼容的方法總結(jié)
js與自動(dòng)伸縮圖片 自動(dòng)縮小圖片的多瀏覽器兼容的方法總結(jié)...2007-03-03符合web標(biāo)準(zhǔn)的連續(xù)滾動(dòng)圖像的js代碼
符合web標(biāo)準(zhǔn)的連續(xù)滾動(dòng)圖像的js代碼...2007-02-02