【问题标题】:Scale image on seperate div hover在单独的 div 悬停上缩放图像
【发布时间】:2017-06-14 09:03:16
【问题描述】:

见:https://jsfiddle.net/8osg70fp/

当另一侧的 div 悬停在页面右侧时,我想像小提琴一样缩放页面右侧的图像。

我知道这种格式的东西,但我无法让它工作。

var treecontainer=document.getElementById('treecontainer'); //DIV=TREECONTAINER
$(treecontainer).mouseover(function(){
    /*CHANGE IMAGE'S CSS HERE*/    
});
$(treecontainer).mouseleave(function(){
    /*CHANGE IMAGE'S CSS BACK HERE*/    
});

【问题讨论】:

  • 所以你能把你的html和你的脚本代码一起粘贴,让我们知道什么是不工作的。如果你能为你的问题创建一个小提琴示例会更好
  • 能否贴出完整的相关代码。

标签: javascript jquery html css image


【解决方案1】:

请看一看。如果这不是您需要的,请告诉我。

.container {
  display: flex;
  justify-content: space-between;
  margin: 20px;
}

.myhover {
  width: 100px;
  height: 100px;
  background-color: blue;
}

.myhover:hover + .scaleme {
  transform: scale(1.2);
}
<div class="container">
  <div class="myhover"></div>
  <img class="scaleme" src="http://placehold.it/100">
</div>

【讨论】:

    【解决方案2】:

    我想这就是你要找的东西

    js

      $('div').mouseenter(function(){
         $('.secondone').css({transform:'scale(1.5)'});
     });
    $('div').mouseleave(function(){
         $('.secondone').css({transform:'scale(1)'});
     });
    

    css

    div {
      height:200px;
      width:200px;
      background-color:black;
      margin:5% 30%;
      transition:.5s ease;
    }
    
    <div></div>
    <div class="secondone"></div>
    

    https://codepen.io/anon/pen/JJREbL

    【讨论】:

      【解决方案3】:

      您不需要任何 javascript 来执行此操作。如果您对悬停状态使用 CSS 缩放转换,您将获得完全相同的效果,而无需使用不必要的 JavaScript。

      只有几行 CSS

      div {
          height:200px;
          width:200px;
          background-repeat: no-repeat;
          background-size: contain;
          background-image: url(https://source.unsplash.com/random);
          transition:.5s ease;
      }
      
      div.first:hover + div.second {
          transform: scale(1.2);
      }
      

      检查我的笔 - https://codepen.io/Legues/pen/LLRxQg

      【讨论】:

        【解决方案4】:

        试试这个:

        CSS

        div {
        margin: 150px;
        width: 200px;
        height: 100px;
        background-color: yellow;
        border: 1px solid black;
        transition: all 3s;
        }
        
        .div1:hover+ .div2 {
         border: 1px solid black;
        -ms-transform: scale(2,3); /* IE 9 */
        -webkit-transform: scale(2,3); /* Safari */
        transform: scale(2,3); /* Standard syntax */
        transition: all 3s;
        }
        

        网址:Check demo

        【讨论】:

          猜你喜欢
          • 2016-06-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-03-13
          • 1970-01-01
          • 2016-08-18
          相关资源
          最近更新 更多