国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery實(shí)現(xiàn)可拖拽3D萬花筒旋轉(zhuǎn)特效

2019-11-19 18:10:33
字體:
供稿:網(wǎng)友

這是一個(gè)使用了CSS3立體效果的強(qiáng)大特效,本特效使用jQuery跟CSS3 transform來實(shí)現(xiàn)在用戶鼠標(biāo)按下拖動(dòng)時(shí),環(huán)形圖片墻可以跟隨鼠標(biāo)進(jìn)行3D旋轉(zhuǎn)動(dòng)畫。

進(jìn)去后可以上下左右的拖動(dòng)圖片。

本示例中使用到了CSS3的transform-style 屬性,該規(guī)定如何在 3D 空間中呈現(xiàn)被嵌套的元素。

默認(rèn)值: flat

繼承性: no

版本: CSS3

JavaScript 語法: object.style.transformStyle="preserve-3d"

有2個(gè)屬性值可選擇:

flat 子元素將不保留其 3D 位置。

preserve-3d 子元素將保留其 3D 位置。

示例代碼如下:

<!DOCTYPE html><html lang="zh"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"><title>jQuery可拖拽3D萬花筒旋轉(zhuǎn)特效 - 何問起</title><base target="_blank" /><style type="text/css"> *{margin:0;padding: 0;} .hovertree{ width: 120px; height: 180px; margin: 150px auto 0; position: relative; /*transform 旋轉(zhuǎn)元素*/ transform-style:preserve-3d; transform:perspective(800px) rotateX(-10deg) rotateY(0deg); } body{background-color: #66677c;} .hovertree img{ position: absolute; width: 100%; height: 100%; border-radius: 5px; box-shadow: 0px 0px 10px #fff; /*倒影的設(shè)置*/ -webkit-box-reflect:below 10px -webkit-linear-gradient(top,rgba(0,0,0,0) 50%,rgba(0,0,0,.5) 100%); } .hovertree p{ width: 1200px; height: 1200px; background: -webkit-radial-gradient(center center,600px 600px,rgba(255,255,255,.5),rgba(0,0,0,0)); position: absolute; top:100%;left:50%; margin-top: -600px; margin-left: -600px; border-radius:600px; transform:rotateX(90deg); } .hewenqi{position:absolute;z-index:99;} a{color:blue;}</style></head><body><div class="hovertree"> <img src="http://hovertree.com/texiao/css/14/hovertreepic/01.jpg"/> <img src="http://hovertree.com/texiao/css/14/hovertreepic/02.jpg" /> <img src="http://cms.hovertree.com/hvtimg/201511/9rour12a.jpg"/> <img src="http://hovertree.com/texiao/css/14/hovertreepic/04.jpg"/> <img src="http://hovertree.com/texiao/css/14/hovertreepic/05.jpg"/> <img src="http://hovertree.com/texiao/css/14/hovertreepic/06.jpg"/> <img src="http://hovertree.com/texiao/css/14/hovertreepic/07.jpg"/> <img src="http://hovertree.com/texiao/css/14/hovertreepic/08.jpg"/> <img src="http://hovertree.com/hvtimg/201511/6j9j6tk5.png"/> <img src="http://cms.hovertree.com/hvtimg/201512/wfevf6yh.jpg"/> <p></p></div><script src="http://down.hovertree.com/jquery/jquery-1.11.0.min.js" type="text/javascript"></script><script type="text/javascript"> $(function(){var imgL=$(".hovertree img").size();var deg=360/imgL;var roY=0,roX=-10; var xN=0,yN=0; var play=null; $(".hovertree img").each(function (i) { $(this).css({ //<!--translateZ 定義2d旋轉(zhuǎn)沿著z軸--> "transform":"rotateY("+i*deg+"deg) translateZ(300px)" }); //<!--防止圖片被拖拽--> $(this).attr('ondragstart','return false'); }); $(document).mousedown(function(ev){ var x_=ev.clientX; var y_=ev.clientY; clearInterval(play); console.log('我按下了'); $(this).bind('mousemove',function(ev){  /*獲取當(dāng)前鼠標(biāo)的坐標(biāo)*/  var x=ev.clientX;  var y=ev.clientY;  /*兩次坐標(biāo)之間的距離*/  xN=x-x_;  yN=y-y_;  roY+=xN*0.2;  roX-=yN*0.1;  console.log('移動(dòng)');  //$('body').append('<div style="width:5px;height:5px;position:absolute;top:'+y+'px;left:'+x+'px;background-color:red"></div>');  $('.hovertree').css({   transform:'perspective(800px) rotateX('+roX+'deg) rotateY('+roY+'deg)'  });  /*之前的鼠標(biāo)坐標(biāo)*/  x_=ev.clientX;  y_=ev.clientY; }); }).mouseup(function(){  $(this).unbind('mousemove');  var play=setInterval(function(){  xN*=0.95;  yN*=0.95  if(Math.abs(xN)<1 && Math.abs(yN)<1){  clearInterval(play);  }  roY+=xN*0.2;  roX-=yN*0.1;  $('.hovertree').css({   transform:'perspective(800px) rotateX('+roX+'deg) rotateY('+roY+'deg)'  });  },30); });});</script><div style="text-align:center;margin:250px 0; font:normal 14px/24px 'MicroSoft YaHei';"> <p class="hewenqi">來源:<a >何問起</a> <a >說明</a></p></div></body></html>

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持武林網(wǎng)!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 桃江县| 定远县| 大安市| 潜山县| 平江县| 中阳县| 蓬安县| 黄平县| 镇雄县| 老河口市| 休宁县| 郑州市| 茌平县| 米泉市| 东乌| 揭西县| 台北市| 汉阴县| 金塔县| 班戈县| 德江县| 泰兴市| 北川| 南安市| 长阳| 南皮县| 蓝山县| 南木林县| 上犹县| 黄平县| 广丰县| 湘潭市| 金秀| 遂宁市| 太和县| 西城区| 玛纳斯县| 恩施市| 抚宁县| 梁河县| 兰坪|