jquery – 如何显示部分标题并在悬停时向上滑动整个标题

前端之家收集整理的这篇文章主要介绍了jquery – 如何显示部分标题并在悬停时向上滑动整个标题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下小提琴: http://jsfiddle.net/nyube8aw/

HTML:

  1. <div class="Box">
  2. <div class="caption">
  3. <h3>This is Image One</h3>
  4. <p>Lorem ipsum dolor sit amet,consectetur adipiscing elit. Nulla commodo dolor in dui lacinia gravida.</p>
  5. </div>
  6. <img src="http://i.stack.imgur.com/46ccz.jpg" />
  7. </div>

如何修改代码以使H3在悬停时保持可见,从而滚动整个内容.

解决方法

另一种方法是jQuery动画.请参见下面的示例.
  1. $(document).ready(function() {
  2. $('.Box').mouseenter(function(){
  3. $('.caption').stop().animate({height: "94%"});
  4. });
  5. $('.Box').mouseleave(function(){
  6. $('.caption').stop().animate({height: "15%"},500,function() {
  7. });
  8. });
  9. });
  1. .Box {
  2. position: relative;
  3. float: left;
  4. width: 300px;
  5. height: 300px;
  6. margin-right: 20px;
  7. }
  8. .last {
  9. margin-right: 0;
  10. }
  11. .caption {
  12. position: absolute;
  13. background: #000;
  14. opacity: 0.7;
  15. bottom: 0;
  16. left: 0;
  17. width: 90%;
  18. height: 15%; /* Auto can still work for the height */
  19. padding: 5%;
  20. color: #fff;
  21. padding-top:1%;
  22. }
  23. .full-height {
  24. height: 90%;
  25. }
  26. }
  1. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  2. <div class="Box">
  3. <div class="caption">
  4. <h3>This is Image One</h3>
  5. <p>Lorem ipsum dolor sit amet,consectetur adipiscing elit. Nulla commodo dolor in dui lacinia gravida.</p>
  6. </div>
  7. <img src="http://i.stack.imgur.com/46ccz.jpg" />
  8. </div>

See on Fiddle

注意:请在整个屏幕上全屏查看它的工作情况,

猜你在找的jQuery相关文章