Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用Image或Image onClick=Flip(';ID NAME';)翻转Div;_Javascript_Jquery - Fatal编程技术网

Javascript 用Image或Image onClick=Flip(';ID NAME';)翻转Div;

Javascript 用Image或Image onClick=Flip(';ID NAME';)翻转Div;,javascript,jquery,Javascript,Jquery,我想水平和垂直翻转图像我怎么做?通过其id单击函数 <script> function fliph(imageid){ var imageid = imageid; //What Should I have to Type HERE??? } function flipv(imageid){ var imageid = imageid; //What Should I have to Type H

我想水平和垂直翻转图像我怎么做?通过其id单击函数

<script>
    function fliph(imageid){
        var imageid = imageid;
        //What Should I have to Type HERE???
    }
    function flipv(imageid){
        var imageid = imageid;
        //What Should I have to Type HERE???
    }
</script>
<input type="submit" name="flip" value="Flip Horizontal" onClick="fliph('imageid')" />
<input type="submit" name="flip" value="Flip Vertical" onClick="flipv('imageid')" />
<img src="http://classihome.com/uploads/gallery/1453292889developlda.jpg" id="imageid">

函数fliph(imageid){
var imageid=imageid;
//我应该在这里输入什么???
}
函数flipv(图像ID){
var imageid=imageid;
//我应该在这里输入什么???
}

这两个函数都是通过提供的id查找元素,然后分别切换
.flipv
.fliph

然后,我们使用CSS变换来缩放图像

注意:我使用的是
classList
,它是本机JavaScript,但在较旧的浏览器中不起作用。如果您已经在使用jQuery,我建议您使用类似于
$('#'+imageid)的东西取而代之

函数fliph(imageId){
var el=document.getElementById(imageId);
el.classList.toggle('fliph');
}
函数flipv(图像ID){
var el=document.getElementById(imageId);
el.classList.toggle('flipv');
}
.flipv{
变换:scaleY(-1);
}
弗利普先生{
转换:scaleX(-1);
}
.flipv.fliph{
变换:比例(-1,-1);
}

这两个函数都是通过提供的id查找元素,然后分别切换
.flipv
.fliph

然后,我们使用CSS变换来缩放图像

注意:我使用的是
classList
,它是本机JavaScript,但在较旧的浏览器中不起作用。如果您已经在使用jQuery,我建议您使用类似于
$('#'+imageid)的东西取而代之

函数fliph(imageId){
var el=document.getElementById(imageId);
el.classList.toggle('fliph');
}
函数flipv(图像ID){
var el=document.getElementById(imageId);
el.classList.toggle('flipv');
}
.flipv{
变换:scaleY(-1);
}
弗利普先生{
转换:scaleX(-1);
}
.flipv.fliph{
变换:比例(-1,-1);
}

我假设翻转意味着旋转90度。这样你可以有四个步骤。 您将访问图像元素的样式属性

这就是您的代码应该是什么样子

<body>

   <img id="imageId" style="border:1px solid blue; width:50px; height:30px;">

   <button onclick="flip('imageId')"/> 


</body>
<script>
var deg = 90;
var currentRotation = 0;
function flip(imageId){
   var imageRef = document.getElementById(imageId); 
   if(currentRotation === 270){ 
    currentRotation = 0; 
} 
else {
        currentRotation += deg;
}

imageRef.style.webkitTransform = 'rotate('+currentRotation+'deg)'; 
imageRef.style.mozTransform    = 'rotate('+currentRotation+'deg)'; 
imageRef.style.msTransform     = 'rotate('+currentRotation+'deg)'; 
imageRef.style.oTransform      = 'rotate('+currentRotation+'deg)'; 
imageRef.style.transform       = 'rotate('+currentRotation+'deg)'; 
}
</script>
</html>

var-deg=90;
var currentRotation=0;
函数翻转(imageId){
var imageRef=document.getElementById(imageId);
如果(当前旋转===270){
电流旋转=0;
} 
否则{
电流旋转+=度;
}
imageRef.style.WebKittTransform='rotate('+currentRotation+'deg');
imageRef.style.mozTransform='rotate('+currentRotation+'deg');
imageRef.style.msTransform='rotate('+currentRotation+'deg');
imageRef.style.oTransform='旋转('+currentRotation+'deg');
imageRef.style.transform='旋转('+currentRotation+'deg');
}

我假设翻转意味着旋转90度。这样你可以有四个步骤。 您将访问图像元素的样式属性

这就是您的代码应该是什么样子

<body>

   <img id="imageId" style="border:1px solid blue; width:50px; height:30px;">

   <button onclick="flip('imageId')"/> 


</body>
<script>
var deg = 90;
var currentRotation = 0;
function flip(imageId){
   var imageRef = document.getElementById(imageId); 
   if(currentRotation === 270){ 
    currentRotation = 0; 
} 
else {
        currentRotation += deg;
}

imageRef.style.webkitTransform = 'rotate('+currentRotation+'deg)'; 
imageRef.style.mozTransform    = 'rotate('+currentRotation+'deg)'; 
imageRef.style.msTransform     = 'rotate('+currentRotation+'deg)'; 
imageRef.style.oTransform      = 'rotate('+currentRotation+'deg)'; 
imageRef.style.transform       = 'rotate('+currentRotation+'deg)'; 
}
</script>
</html>

var-deg=90;
var currentRotation=0;
函数翻转(imageId){
var imageRef=document.getElementById(imageId);
如果(当前旋转===270){
电流旋转=0;
} 
否则{
电流旋转+=度;
}
imageRef.style.WebKittTransform='rotate('+currentRotation+'deg');
imageRef.style.mozTransform='rotate('+currentRotation+'deg');
imageRef.style.msTransform='rotate('+currentRotation+'deg');
imageRef.style.oTransform='旋转('+currentRotation+'deg');
imageRef.style.transform='旋转('+currentRotation+'deg');
}

检查这两个链接并将其合并…如果可能,使用jQuery…@SamGhatak您显示的链接非常完美。但是,当我复制它们时,它们不工作。任何脚本文件都必须附加。你能给我一个我尝试过的链接吗。检查这两个链接并合并…如果可能,使用jQuery…@SamGhatak您显示的链接非常完美。但是,当我复制它们时,它们不工作。任何脚本文件都必须附加。你能给我一个我尝试过的链接吗。你做得很好,但它不会水平移动。请用水平更新。你做得很好,但它不会水平移动。请用水平更新。