jQuery開發之超連結提示效果和圖片提示效果,jquery超連結

來源:互聯網
上載者:User

jQuery開發之超連結提示效果和圖片提示效果,jquery超連結

1,超連結提示效果
超連結內建的有提示效果的,這裡就把自己定義的提示效果放在一起可以進行一下比較。範例程式碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=GB18030"><title>jQuery test </title><script type ="text/javascript" src ="jquery.js" ></script><script type ="text/javascript">$(document).ready(function(){    var x = 10;    var y = 20;    $("a.tooltip").mouseover(function(e){    this.myTitle =  this.title;    this.title ="";    var tooltip ="<div id ='tooltip'>"+this.myTitle+"</div>";    $("body").append(tooltip);  //將它追加到文檔中    $("#tooltip").css({"top":(e.pageY+y)+"px","left":(e.pageX+x)+"px","color":"#00ff00"}).show("fast");//設定x座標和y座標,並顯示    })    .mouseout(function(){        this.title = this.myTitle;        $("#tooltip").remove();   //移除    })    .mousemove(function(e){        $("#tooltip").css({"top":(e.pageY+y)+"px","left":(e.pageX+x)+"px","color":"#00ff00"});    });});</script></head><body><p><a href ="#" class ="tooltip" title ="這是我的超級連結提示1.">提示1.</a></p><p><a href ="#" class ="tooltip" title ="這是我的超級連結提示2.">提示2.</a></p><p><a href ="#" title ="內建提示1.">內建提示1.</a></p><p><a href ="#" title ="內建提示2.">內建提示2.</a></p></body></html>

運行效果如下:

可以看到自訂的提示效果可以實現的效果更好些。而且可以設定的樣式更多,是網頁看起來更加的好看。

2,圖片提示效果
範例程式碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=GB18030"><title>jQuery test </title><script type ="text/javascript" src ="jquery.js" ></script><script type ="text/javascript">$(document).ready(function(){    var x = 10;    var y = 20;    $("a.tooltip").mouseover(function(e){    this.myTitle =  this.title;    this.title ="";    var imgTitle =this.myTitle?"<br/>"+this.myTitle:+"";    var tooltip ="<div id ='tooltip'><img src='"+this.href+"' alt ='圖片預覽'/>"+this.myTitle+"</div>";//這個地方要特別注意,要給this.href 外面添加單引號    $("body").append(tooltip);  //將它追加到文檔中    $("#tooltip").css({"top":(e.pageY+y)+"px","left":(e.pageX+x)+"px","color":"#00ff00"}).show("fast");//設定x座標和y座標,並顯示    })    .mouseout(function(){        this.title = this.myTitle;        $("#tooltip").remove();   //移除    })    .mousemove(function(e){        $("#tooltip").css({"top":(e.pageY+y)+"px","left":(e.pageX+x)+"px","color":"#00ff00"});    });});</script></head><body><ul><li><a href ="http://img0.bdstatic.com/img/image/shouye/sheying0617.jpg" class ="tooltip" title ="小鳥"><img src ="http://img0.bdstatic.com/img/image/shouye/sheying0617.jpg" alt ="小鳥照片"  /></a></li><li><a href ="http://img0.bdstatic.com/img/image/shouye/bizhi0617.jpg" class ="tooltip" title ="鮮花" ><img src ="http://img0.bdstatic.com/img/image/shouye/bizhi0617.jpg" alt ="鮮花圖片"  /></a></li></ul></body></html>

運行效果如下:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.