js常用效果

來源:互聯網
上載者:User

標籤:返回頂部   style   blog   http   io   ar   color   os   使用   

//建立元素var txt1="<p style=‘color:red‘>我是由HTML建立的</p>";               // 以 HTML 建立新元素var txt2=$("<p></p>").text("我是由JQuery建立的");                   // 以 jQuery 建立新元素      txt2.css({"color":"blue"}) ;                                  // JQuery CSSvar txt3=document.createElement("p");      txt3.innerHTML="我是由DOM建立的.";                            // 通過 DOM 來建立文本      txt3.style.color="green";                                     // DOM CSS$("body").append(txt1,txt2,txt3);                                   // 追加新元素//右鍵菜單$(document).bind("contextmenu",function(e){        return false;});//獲得滑鼠指標XY值$(document).mousemove(function(e){    $(‘#xy‘).html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);});//jQuery延時載入功能  window.setTimeout(function() {     // do something}, 1000);//使元素居螢幕中間位置 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");      return this;  }//.當圖片沒有正確引用時使用預設的圖片  $("img").error(function () {          $(this).unbind("error").attr("src", "http://s0.hao123img.com/res/img/logo/logonew.png"); });//.回到頂部效果$(window).scroll(function() {   //返回頂部       if ($(this).scrollTop() > 150){            $(‘#top‘).fadeIn(1000);       } else {            $(‘#top‘).fadeOut(1000);        } });  $(‘#top‘).click(function(event) {                $("html,body").animate({scrollTop: 0}, 2000); })//回到底部$("#toBottom").click(function () {    $("html,body").animate({ "scrollTop":$(document).height()}, 1000);});$(window).scroll(function(){     //左側浮動廣告  $("#left").stop(true,false).delay(200).animate({top:$(window).scrollTop()+250},"slow")}) $(window).scroll(function(){    //中間固定定位if($(this).scrollTop()>100){$("#center").css({"position":"fixed","top":"0px"})}else{$("#center").css({"position":"absolute","top":"100px"})}}) 

 

js常用效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.