javascript – 添加选择下拉框以点击交换图像js

前端之家收集整理的这篇文章主要介绍了javascript – 添加选择下拉框以点击交换图像js前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个javascript,当你点击图像时它会改变图像scr,它将循环通过.它还有箭头键盘导航的分页链接.我想要做的是添加一个选择下拉列表框,允许我跳转到我想要的任何图像.我怎样才能做到这一点?我只想要一个没有提交按钮的选择下拉列表

  1. /* set first image in frame from #shoeBox on document.ready */
  2. $(function() {
  3. var leadOff = $('#shoeBox img:first-child').attr('source');
  4. $('.picture').attr({'src' : leadOff,'imageposition' : '1'});
  5. });
  6. /* load next image from #shoeBox (click on image and/or next button) */
  7. $('#pictureframe,#buttonright').click(function() {
  8. var imageTally = $('#shoeBox img').length;
  9. var imagePosition = $('.picture').attr('imageposition');
  10. var plusOne = parseInt(imagePosition) + 1;
  11. var nextUp = $('#shoeBox img:nth-child(' + plusOne + ')').attr('source');
  12. if (imagePosition == imageTally) {
  13. var leadOff = $('#shoeBox img:first-child').attr('source');
  14. $('.picture').attr({'src' : leadOff,'imageposition' : '1'});
  15. } else {
  16. $('.picture').attr({'src' : nextUp,'imageposition' : plusOne});
  17. }
  18. });
  19. /* load prevIoUs image from #shoeBox (click on prev button) */
  20. $('#buttonleft').click(function() {
  21. var imageTally = $('#shoeBox img').length;
  22. var imagePosition = $('.picture').attr('imageposition');
  23. var minusOne = parseInt(imagePosition) - 1;
  24. var nextUp = $('#shoeBox img:nth-child(' + minusOne + ')').attr('source');
  25. if (imagePosition == '1') {
  26. var lastPic = $('#shoeBox img:last-child').attr('source');
  27. $('.picture').attr({'src' : lastPic,'imageposition' : imageTally});
  28. } else {
  29. $('.picture').attr({'src' : nextUp,'imageposition' : minusOne});
  30. }
  31. });
  32. /* Add arrow keyboard navigation */
  33. function GoToLocation(url)
  34. {
  35. window.location = url;
  36. }
  37. Mousetrap.bind("right",function() {
  38. document.getElementById('buttonright').click();
  39. });
  40. function GoToLocation(url)
  41. {
  42. window.location = url;
  43. }
  44. Mousetrap.bind("left",function() {
  45. document.getElementById('buttonleft').click();
  46. });
  1. body {
  2. display: flex;
  3. justify-content: center;
  4. align-items: center;
  5. height: 100vh;
  6. width: 100%;
  7. }
  8. #wall {
  9. display: flex;
  10. flex-direction: column;
  11. padding: 6px;
  12. background-color: hsla(0,0%,20%,1);
  13. }
  14. #pictureframe {
  15. display: flex;
  16. padding: 6px;
  17. background-color: hsla(0,40%,1);
  18. }
  19. #pictureframe img {
  20. display: flex;
  21. width: 100px;
  22. height: 100px;
  23. }
  24. #buttonswrapper {
  25. display: flex;
  26. flex-grow: 1;
  27. }
  28. #buttonleft,#buttonright {
  29. display: flex;
  30. justify-content: center;
  31. align-items: center;
  32. flex-grow: 1;
  33. padding: 6px;
  34. color: hsla(40,70%,1);
  35. font-variant: small-caps;
  36. font-weight: bold;
  37. font-family: Verdana,sans-serif;
  38. background-color: hsla(0,1);
  39. cursor: pointer;
  40. }
  41. #buttonleft:hover,#buttonright:hover {
  42. background-color: hsla(50,50%,1);
  43. }
  44. #shoeBox {
  45. display: none;
  46. }

猜你在找的HTML相关文章