標籤:返回頂部 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常用效果