導航:首頁 > 編程語言 > js圖片疊加旋轉切換

js圖片疊加旋轉切換

發布時間:2023-01-27 05:41:38

『壹』 html,jquery怎樣實現圖片旋轉中換圖的時候不只是兩張圖片的切換,而是從本地調用到多張圖片進行循環

把變換的圖片都寫在html中,拉動距離實現,

『貳』 js 怎麼實現點擊一次圖片旋轉90度,再點擊再轉90度呢

現在我們以這個蘋果的圖片作為例子

『叄』 js實現頁面的指定圖片在不停的旋轉,怎麼實現呢有代碼參考嗎謝謝

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#div1 {
width: 800px;
height: 600px;
background-color: #ff0;
position: absolute;
}
.imgRotate {
width: 100px;
height: 80px;
position: absolute;
top: 50%;
left: 50%;
margin: -40px 0 0 -50px;
}
</style>
</head>
<body>
<div id="div1">
<img id="img1" class="imgRotate" src="http://www..com/img/logo-yy.gif" />
<input id="input2" type="button" value="btn2"></input>
</div>
</body>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jQueryRotate.js"></script>
<script type="text/javascript">
var num = 0;
$("#input2").click(function(){
num ++;
$("#img1").rotate(90*num);
});
</script>
</html>

『肆』 js設置圖片隨機旋轉角度

旋轉.js的代碼如下:

var ele ;

//自定義函數
$.fn.extend({
rotate: function () {
ele = this ;
setInterval('singleRotate()',20);
}
});

//初始角度
var degree = 0;

//單次旋轉
function singleRotate() {
//一次增加50度
degree = degree + 50 * Math.PI / 180;
ele.css("transform","rotate("+degree+"deg)");
}

代碼中只需引用一下js就行了,我將其封裝後放在了伺服器上,大家可以直接引用

1

<script src="http://libs.codeboy.me/js/rotate/1.0/rotate.js"></script>

引用前記得引用jquery,最後在自己的代碼中調用rotate方法即可。

1

$(element).rotate();

『伍』 尋網頁中JS實現的圖片切換特效

我修改測試通過一個。但是有個問題。若改成滑鼠懸停邊緣滾下去,也就是onMouseOver。是停不下來的,會一直滾下去,因為無論怎麼樣都是滑鼠碰觸事件。所以我強烈建議用點擊事件,onclick。
js css image都是調用的。我都寫到頁面里了,你自己改下。圖片地址我沒改。本地測試的。自己換成你的圖片。

<!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=utf-8">
<title>圖片展示特效</title>
<style>
body{ margin:20px auto; width:100%; height:auto;}
#dHomePageCarousel {
height:221px;
width:670px;
position:relative;
margin:40px auto;
}
#dLocalHomesCarousel {
height:131px;
margin:0px 2px 3px 1px;
overflow:hidden;
position:relative;
}
.divCarouselInfo {
color:#3C404E;
font-size:12px;
width:639px;
height:64px;
line-height:16px;
margin-right:15px;
padding-top:10px;
position:relative;
}
.imgBorder{
border:2px solid #fff;
position:absolute;
cursor:pointer;
}
.imgBorder:hover {
border:2px solid #FFAA55;
cursor:pointer;
position:absolute;
}
.btnCarouselLT {
background:url("../images/btn_nav_carousel.png") no-repeat scroll left top transparent;
display:block;
height:41px;
overflow:hidden;
position:absolute;
cursor:pointer;
top:17px;
width:40px;
}
.btnCarouselRT {
background:url("../images/btn_nav_carousel.png") no-repeat scroll right top transparent;
display:block;
height:41px;
overflow:hidden;
position:absolute;
cursor:pointer;
top:17px;
width:40px;
}

img {
border:medium none;
}

.author{ width:700px; margin:0 auto; height:auto; text-align:center;}

</style>
</head>
<body onLoad="clearInterval(autoplay);">
<!-- 頭開始 -->
<!-- 滾動房源廣告開始 -->
<div id="dHomePageCarousel" style="padding-left:15px">
<div id=dLocalHomesCarousel>
<img id="imgSmallLeft" class="imgBorder" style="height:50px; width:70px; left:10px; bottom:5px;" onClick="clearInterval(autoplay);moveD('l');"/>
<img id="imgMiddleLeft" class="imgBorder" style="height:75px; width:100px; left:110px; bottom:5px;" onClick="clearInterval(autoplay);move('l');"/>
<img id="imgBig" class="imgBorder" style="height:105px; width:140px; left:240px; bottom:5px;" onClick="openNewPage();"/>
<img id="imgMiddleRight" class="imgBorder" style="height:75px; width:100px; left:410px; bottom:5px;" onClick="clearInterval(autoplay);move('r');"/>
<img id="imgSmallRight" class="imgBorder" style="width:70px; height:50px; left:540px; bottom:5px;" onClick="clearInterval(autoplay);moveD('r');"/>
<img id="imgHidden" class="imgBorder" style="width:10px; height:10px; left:-90px; bottom:5px;"/>
</div>
<script type="text/javascript">
function AdItem(Photo,url) {
this.Photo = Photo;
this.url = url;
}
var ad = new Array();
ad[0] = new AdItem('images/1.jpg','#'); ad[1] = new AdItem('images/2.jpg','#'); ad[2] = new AdItem('images/3.jpg','#'); ad[3] = new AdItem('images/4.jpg','#'); ad[4] = new AdItem('images/5.jpg','#'); ad[5] = new AdItem('images/6.jpg','#'); ;
var img = new Array();
img[0] = document.getElementById("imgSmallLeft");
img[1] = document.getElementById("imgMiddleLeft");
img[2] = document.getElementById("imgBig");
img[3] = document.getElementById("imgMiddleRight");
img[4] = document.getElementById("imgSmallRight");
img[5] = document.getElementById("imgHidden");

var position = 0;
for(i=0;i<img.length;i++){
img[i].src = ad[i].Photo;
}

var cur = 2;
adname.href = ad[2].url;
</script>
</div>
<script type="text/javascript">

function roll(direction){
var imgLength = img.length;
var dataLength = ad.length;
var start = position;
if('r' == direction){
for(var i=0; i<imgLength; i++){
start = start + 1;
if(start > (dataLength-1))
start = start - dataLength;
img[i].src = ad[start].Photo;
}
position = position + 1;
if(position > (dataLength-1))
position = position - dataLength;
}
if('l' == direction){
var a = true;
for(var i=0; i<imgLength; i++){
if(a){
start = start - 1;
if(start < 0){
start = start + dataLength;
a = false;
}
if(start < (dataLength-1)){
a = false;
}
}else{
start = start + 1;
if(start > (dataLength-1)){
start = start - dataLength;
a = true;
}
}
//alert(position + " === " + i + " === " + start);
img[i].src = ad[start].Photo;
if(start == (dataLength-1)){
start = -1;
}
}
position = position - 1;
if(position < 0)
position = position + dataLength;
}
}

function right(){
i++;
var img0H = parseFloat(img[0].style.height);
var img0W = parseFloat(img[0].style.width);
var img0L = parseFloat(img[0].style.left);
var img1H = parseFloat(img[1].style.height);
var img1W = parseFloat(img[1].style.width);
var img1L = parseFloat(img[1].style.left);
var img2H = parseFloat(img[2].style.height);
var img2W = parseFloat(img[2].style.width);
var img2L = parseFloat(img[2].style.left);
var img3H = parseFloat(img[3].style.height);
var img3W = parseFloat(img[3].style.width);
var img3L = parseFloat(img[3].style.left);
var img4H = parseFloat(img[4].style.height);
var img4W = parseFloat(img[4].style.width);
var img4L = parseFloat(img[4].style.left);
var img5H = parseFloat(img[5].style.height);
var img5W = parseFloat(img[5].style.width);
var img5L = parseFloat(img[5].style.left);

//解決IE兼容性問題
if(navigator.userAgent.indexOf("MSIE")>0 && i%2==0) {
img1W = img1W + 1;
img2H = img2H + 1;
img2L = img2L + 1;
img3H = img3H + 1;
img3L = img3L + 1;
img4L = img4L + 1;
img4W = img4W + 1;
}

img[0].style.height = (img0H - 2).toString() + "px";
img[0].style.left = (img0L - 5).toString() + "px";
img[0].style.width = (img0W - 3).toString() + "px";

img[1].style.height = (img1H - 1).toString() + "px";
img[1].style.left = (img1L - 5).toString() + "px";
img[1].style.width = (img1W - 1.5).toString() + "px";

img[2].style.height = (img2H - 1.5).toString() + "px";
img[2].style.left = (img2L - 6.5).toString() + "px";
img[2].style.width = (img2W - 2).toString() + "px";

img[3].style.height = (img3H + 1.5).toString() + "px";
img[3].style.left = (img3L - 8.5).toString() + "px";
img[3].style.width = (img3W + 2).toString() + "px";

img[4].style.height = (img4H + 1).toString() + "px";
img[4].style.left = (img4L - 6.5).toString() + "px";
img[4].style.width = (img4W + 1.5).toString() + "px";

img[5].style.height = (img5H + 2).toString() + "px";
img[5].style.left = (img5L - 5).toString() + "px";
img[5].style.width = (img5W + 3).toString() + "px";
//alert(img[1].style.width);
if(i>19){
clearInterval(hide);
reset();
roll('r');
isRunning = 'false';
}
}

function left(){
i++;
var img0H = parseFloat(img[0].style.height);
var img0W = parseFloat(img[0].style.width);
var img0L = parseFloat(img[0].style.left);
var img1H = parseFloat(img[1].style.height);
var img1W = parseFloat(img[1].style.width);
var img1L = parseFloat(img[1].style.left);
var img2H = parseFloat(img[2].style.height);
var img2W = parseFloat(img[2].style.width);
var img2L = parseFloat(img[2].style.left);
var img3H = parseFloat(img[3].style.height);
var img3W = parseFloat(img[3].style.width);
var img3L = parseFloat(img[3].style.left);
var img4H = parseFloat(img[4].style.height);
var img4W = parseFloat(img[4].style.width);
var img4L = parseFloat(img[4].style.left);
var img5H = parseFloat(img[5].style.height);
var img5W = parseFloat(img[5].style.width);
var img5L = parseFloat(img[5].style.left);

//解決IE兼容性問題
if(navigator.userAgent.indexOf("MSIE")>0 && i%2==0) {
img0W = img0W + 1;
img1H = img1H + 1;
img1L = img1L + 1;
img2H = img2H + 1;
img2L = img2L + 1;
img3L = img3L + 1;
img3W = img3W + 1;
}

img[0].style.height = (img0H + 1).toString() + "px";
img[0].style.left = (img0L + 5).toString() + "px";
img[0].style.width = (img0W + 1.5).toString() + "px";

img[1].style.height = (img1H + 1.5).toString() + "px";
img[1].style.left = (img1L + 6.5).toString() + "px";
img[1].style.width = (img1W + 2).toString() + "px";

img[2].style.height = (img2H - 1.5).toString() + "px";
img[2].style.left = (img2L + 8.5).toString() + "px";
img[2].style.width = (img2W - 2).toString() + "px";

img[3].style.height = (img3H - 1).toString() + "px";
img[3].style.left = (img3L + 6.5).toString() + "px";
img[3].style.width = (img3W - 1.5).toString() + "px";

img[4].style.height = (img4H - 2).toString() + "px";
img[4].style.left = (img4L + 5).toString() + "px";
img[4].style.width = (img4W - 3).toString() + "px";

img[5].style.height = (img5H + 2).toString() + "px";
img[5].style.left = (img5L + 5).toString() + "px";
img[5].style.width = (img5W + 3).toString() + "px";
//alert(img[1].style.left);
if(i>19){
clearInterval(hide);
reset();
roll('l');
isRunning = 'false';
}
}
var isRunning;
function move(direction){

//alert(isRunning);
if(isRunning != 'udefined' && isRunning == 'true')
return;
frequency = 20;
if(navigator.userAgent.indexOf("MSIE")>0) {
frequency = 15;
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
frequency = 20;
}
i = 0;
if(direction == 'r'){
cur = cur + 1;
img[5].style.left = "640px";
hide = setInterval("right()", frequency);
isRunning = 'true';
}
if(direction == 'l'){
cur = cur - 1;
img[5].style.left = "-90px";
var pos = position - 1;
if(pos < 0)
pos = pos + ad.length;
img[5].src = ad[pos].Photo;
hide = setInterval("left()", frequency);
isRunning = 'true';
}
if(cur > (ad.length - 1))
cur = 0;
if(cur < 0)
cur = ad.length - 1;
//alert(cur);
adname.href = ad[cur].url;
if(navigator.userAgent.indexOf("Firefox")>0){
adname.textContent = ad[cur].name;
adtel.textContent = ad[cur].phone;
adaddr.textContent = ad[cur].address;
adprice.textContent = ad[cur].price;
adtime.textContent = ad[cur].time;
} else {
adname.innerText = ad[cur].name;
adtel.innerText = ad[cur].phone;
adaddr.innerText = ad[cur].address;
adprice.innerText = ad[cur].price;
adtime.innerText = ad[cur].time;
}
}

function moveC(direction){
if(isRunning != 'true'){
move(direction);
clearInterval(movec);
}
}

function moveD(direction){
move(direction);
if('r' == direction){
movec = setInterval("moveC('r')",5);
} else {
movec = setInterval("moveC('l')",5);
}
}

function reset(){
img[0].style.width = "70px";
img[0].style.height = "50px";
img[0].style.left = "10px";

img[1].style.width = "100px";
img[1].style.height = "75px";
img[1].style.left = "110px";

img[2].style.width = "140px";
img[2].style.height = "105px";
img[2].style.left = "240px";

img[3].style.width = "100px";
img[3].style.height = "75px";
img[3].style.left = "410px";

img[4].style.width = "70px";
img[4].style.height = "50px";
img[4].style.left = "540px";

img[5].style.width = "10px";
img[5].style.height = "10px";
img[5].style.left = "-90px";
}

autoplay = setInterval("move('r')",2000);

function openNewPage(){
window.open(ad[cur].url);
}

</script>
<!-- 滾動房源廣告結束 -->
</body>
</html>

『陸』 javascript如何實現圖片任意角度的旋轉

可以用JAvascript改變這個圖片的css來旋轉他:
這個是css代碼:
img {
transform:rotate(7deg);
-ms-transform:rotate(7deg); /* IE 9 */
-moz-transform:rotate(7deg); /* Firefox */
-webkit-transform:rotate(7deg); /* Safari 和 Chrome */
-o-transform:rotate(7deg); /* Opera */
}

在JAvascript裡面可以先獲取內到這張圖片 設置圖片id = "box"
var img = document.getElementById('box'); 獲取到這個容圖片並用變數記住
img.style.transform = "rotate(90deg)"; 改變這個圖片的css,旋轉90度

完畢!!!

『柒』 js實現圖片之間的相互切換,點擊img2里的圖片,使img2里的圖片跟Img1交換

通過 src 屬性可以獲取圖像標簽的圖像網址,再交換設置新的 src 屬性,就可以實現了。

『捌』 js實現圖片旋轉效果

1、首先准備一個HTML文檔,文檔中准備好兩個圖片,接下來會對這兩個圖片進行旋轉。

『玖』 如何通過js點擊兩張圖片來回切換

首先

if (oImg.src="img/1.png")

是賦值而不是判斷相等, 判斷相等請用==或者===

其次, 你的切換不應當依賴於從元素上讀到的src, 而應當用變數維護當前的狀態

示例

window.onload=function()
{
var
oImg=document.getElementById('img1'),
Picture=['img/1.png','img/2.png'],
Index=0;
oImg.onclick=function()
{
++Index
Index<Picture.length||(Index=0)
oImg.src=Picture[Index]
}
}
閱讀全文

與js圖片疊加旋轉切換相關的資料

熱點內容
word繪圖板 瀏覽:359
蘋果minecraftpe注冊 瀏覽:775
ps怎麼存儲文件卡 瀏覽:728
微信清除緩存圖片恢復 瀏覽:305
安卓app會閃退怎麼解決 瀏覽:429
哪些app背單詞是免費的 瀏覽:889
cf擊殺圖標放哪個文件夾 瀏覽:208
為什麼我的爐石不能查看完整數據 瀏覽:179
蘋果7音量按鍵不回彈 瀏覽:296
u盤兩個系統可以放一個文件夾嗎 瀏覽:538
linuxshell變數累加 瀏覽:386
win10控制面板怎麼看 瀏覽:574
如何編程換裝游戲程序 瀏覽:269
怎麼登錄沭陽縣民政局網站 瀏覽:451
iphone6降級ios7 瀏覽:92
怎麼隱藏三星應用程序圖標不見了 瀏覽:203
可以兼職的app 瀏覽:493
iphone圓角圖標製作 瀏覽:659
建設銀行app怎麼申請 瀏覽:163
系統備份文件夾在哪 瀏覽:998

友情鏈接