0

Есть HTML код:

<div class="articleBlock">
    <img src="wall/bobber-kong.jpg">
</div>

CSS:

.articleBlock {
    background: white;
    border-radius: 10px;
    box-shadow: 0 0 60px rgba(0,0,0,0.5);
    height: 300px;
    margin-top: 5%;
    margin-left: 10%;
    margin-bottom: 5%;
    overflow: hidden;
    position: relative;
    width: 80%;
}

.articleBlock img {
    position: absolute;
    top: -100px;
    width: 100%;
}

Как с помощью jquery сделать так чтобы при наведении на элемент картинка сдвигалась в лево на 66%?

1 ответ 1

1

На jquery

$(document).ready(function() {
  $('.articleBlock').on('mouseenter', function() {
    $('img', this).stop().animate({
      left: '66%'
    }, 500);
  }).on('mouseleave', function() {
    $('img', this).stop().animate({
      left: '0'
    }, 500);
  });
});
.articleBlock {
  background: white;
  border-radius: 10px;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
  height: 300px;
  margin-top: 5%;
  margin-left: 10%;
  margin-bottom: 5%;
  overflow: hidden;
  position: relative;
  width: 80%;
}
.articleBlock img {
  position: absolute;
  top: -100px;
  width: 100%;
  left: 0
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="articleBlock">
  <img src="http://www.untitledmotorcycles.com/wp-content/gallery/bobber-kong_1/bobber-kong05.jpg">
</div>

На CSS3

.articleBlock {
  background: white;
  border-radius: 10px;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
  height: 300px;
  margin-top: 5%;
  margin-left: 10%;
  margin-bottom: 5%;
  overflow: hidden;
  position: relative;
  width: 80%;
}
.articleBlock img {
  position: absolute;
  top: -100px;
  width: 100%;
  left: 0;
  -webkit-transition: left 500ms linear;
  -moz-transition: left 500ms linear;
  -o-transition: left 500ms linear;
  transition: left 500ms linear;
}
.articleBlock:hover img {
  left: 66%;
}
<div class="articleBlock">
  <img src="http://www.untitledmotorcycles.com/wp-content/gallery/bobber-kong_1/bobber-kong05.jpg">
</div>

2
  • Отлично. Спасибо Вам
    – Ezdrael
    15 ноя 2015 в 19:44
  • небольшой update сделал. добавил .stop(). это для того чтобы, если пользователь будет истерично мышкой туда сюда дергать
    – xaja
    15 ноя 2015 в 19:47

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.