{"id":52534,"date":"2024-12-03T11:34:48","date_gmt":"2024-12-03T03:34:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52534\/"},"modified":"2024-12-03T11:34:48","modified_gmt":"2024-12-03T03:34:48","slug":"%e5%9b%be%e7%89%87%e8%bd%ae%e6%92%ad%e6%95%88%e6%9e%9c%e5%ae%9e%e7%8e%b0%e9%97%ae%e9%a2%98%ef%bc%9a%e4%bd%bf%e7%94%a8-transform-translatex-%e5%ae%9e%e7%8e%b0%e5%9b%be%e7%89%87%e5%88%87%e6%8d%a2-3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52534\/","title":{"rendered":"\u56fe\u7247\u8f6e\u64ad\u6548\u679c\u5b9e\u73b0\u95ee\u9898\uff1a\u4f7f\u7528 transform: translateX \u5b9e\u73b0\u56fe\u7247\u5207\u6362\uff0c\u4e3a\u4f55\u6548\u679c\u4e0d\u7406\u60f3\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u56fe\u7247\u8f6e\u64ad\u6548\u679c\u5b9e\u73b0\u95ee\u9898\uff1a\u4f7f\u7528 transform: translateX \u5b9e\u73b0\u56fe\u7247\u5207\u6362\uff0c\u4e3a\u4f55\u6548\u679c\u4e0d\u7406\u60f3\uff1f<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u56fe\u7247\u8f6e\u64ad\u6548\u679c\u5b9e\u73b0\u95ee\u9898\uff1a\u4f7f\u7528 transform: translateX \u5b9e\u73b0\u56fe\u7247\u5207\u6362\uff0c\u4e3a\u4f55\u6548\u679c\u4e0d\u7406\u60f3\uff1f\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241121\/1732164875673ebd0b4aa8e.jpg\" class=\"aligncenter\" title=\"\u56fe\u7247\u8f6e\u64ad\u6548\u679c\u5b9e\u73b0\u95ee\u9898\uff1a\u4f7f\u7528 transform: translateX \u5b9e\u73b0\u56fe\u7247\u5207\u6362\uff0c\u4e3a\u4f55\u6548\u679c\u4e0d\u7406\u60f3\uff1f\u63d2\u56fe\" alt=\"\u56fe\u7247\u8f6e\u64ad\u6548\u679c\u5b9e\u73b0\u95ee\u9898\uff1a\u4f7f\u7528 transform: translateX \u5b9e\u73b0\u56fe\u7247\u5207\u6362\uff0c\u4e3a\u4f55\u6548\u679c\u4e0d\u7406\u60f3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u56fe\u7247\u5207\u6362\u6548\u679c\u5b9e\u73b0<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u672c\u60f3\u5b9e\u73b0\u4e00\u4e2a\u5e38\u89c1\u7684\u56fe\u7247\u8f6e\u64ad\u6548\u679c\uff0c\u5374\u591a\u6b21\u78b0\u58c1\uff0c\u8bf7\u6307\u6559\u95ee\u9898\u6240\u5728\u3002<\/p>\n<p><strong>\u6548\u679c\u5c55\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>\u539f\u6837\u5f0f<\/li>\n<li>\u81ea\u5b9e\u73b0\u6548\u679c<\/li>\n<\/ul>\n<p><strong>\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\n&lt;head&gt;\n  &lt;style&gt;\n    .slider {\n      width: 700px;\n      height: 400px;\n      overflow: hidden;\n      position: relative;\n    }\n\n    .slider-wrapper {\n      width: 700px;\n      height: 400px;\n      position: relative;\n    }\n\n    .slider-wrapper img {\n      width: 700px;\n      height: 400px;\n      position: absolute;\n      top: 0;\n    }\n\n    .indicator {\n      height: 100%;\n      width: 2px;\n      background-color: #fff;\n      position: absolute;\n      top: 0;\n      left: 350px;\n      z-index: 10;\n      cursor: pointer;\n    }\n  &lt;\/style&gt;\n&lt;\/head&gt;\n\n&lt;body&gt;\n  &lt;div class=\"slider\"&gt;\n    &lt;div class=\"slider-wrapper\"&gt;\n      &lt;img id=\"img1\" src=\".\/https:\/\/segmentfault.com\/img\/car1.jpeg\" style=\"z-index: -1000;transform: translateX(-350px);\"&gt;\n      &lt;img id=\"img2\" src=\".\/https:\/\/segmentfault.com\/img\/car2.jpeg\" style=\"z-index: -1001;\"&gt;\n    &lt;\/div&gt;\n    &lt;div class=\"indicator\"&gt;\n      &lt;img style=\"position: absolute;bottom: 40%;transform: translate(-50%,-50%);\" src=\".\/https:\/\/segmentfault.com\/img\/diff-indicator-circle.svg\"\n        alt=\"\"&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n  &lt;script&gt;\n    var slider = document.getElementsByClassName('slider')[0]\n    var indicator = document.getElementsByClassName('indicator')[0]\n    \/\/ \u76d1\u542c\u9f20\u6807\u79fb\u52a8\u4e8b\u4ef6\n    slider.addEventListener(\"mousemove\", function (event) {\n      \/\/ \u83b7\u53d6\u9f20\u6807\u7684\u5750\u6807\n      var x = event.clientX;\n      \/\/ \u8bbe\u7f6ediv\u5143\u7d20\u7684\u4f4d\u7f6e\n      indicator.style.left = x + \"px\";\n      \/\/\u4fee\u6539\u56fe\u7247\u7684\u4f4d\u7f6e\n      var wrapper = document.querySelector('.slider-wrapper');\n      \/\/ wrapper.style.transform = 'translateX(-' + x + 'px)';\n      var img1 = document.getElementById('img1')\n      img1.style.transform = 'translateX(-' + x + 'px)';\n      var img2 = document.getElementById('img2')\n\n    });\n  &lt;\/script&gt;\n&lt;\/body&gt;\n\n&lt;\/html&gt;<\/pre>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><\/p>\n<p>\u5efa\u8bae\u4f7f\u7528 div \u5143\u7d20\u7684 background-image \u5c5e\u6027\uff0c\u5e76\u901a\u8fc7\u6539\u53d8 div \u5143\u7d20\u7684\u5bbd\u5ea6\u6765\u5b9e\u73b0\u56fe\u7247\u7684\u5207\u6362\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u4f7f\u7528 img \u6807\u7b7e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   Go \u4e2d Channel \u914d\u5408 Select \u7684\u610f\u4e49\uff1a\u4e3a\u4ec0\u4e48\u5728\u5904\u7406\u591a\u4e2a Channel \u65f6\uff0cSelect \u6bd4\u76f4\u63a5\u63a5\u6536\u66f4\u6709\u6548\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u56fe\u7247\u8f6e\u64ad\u6548\u679c\u5b9e\u73b0\u95ee\u9898\uff1a\u4f7f\u7528 transform: translateX \u5b9e\u73b0\u56fe\u7247\u5207\u6362\uff0c\u4e3a\u4f55\u6548\u679c\u4e0d\u7406\u60f3\uff1f \u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\u300a\u56fe\u7247\u8f6e\u64ad\u6548\u679c\u5b9e\u73b0\u95ee\u9898\uff1a\u4f7f\u7528 transform: translateX \u5b9e\u73b0\u56fe\u7247\u5207\u6362\uff0c\u4e3a\u4f55\u6548\u679c\u4e0d\u7406\u60f3\uff1f\u300b\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01 \u56fe\u7247\u5207\u6362\u6548\u679c\u5b9e\u73b0 \u95ee\u9898\uff1a \u672c\u60f3\u5b9e\u73b0\u4e00\u4e2a\u5e38\u89c1\u7684\u56fe\u7247\u8f6e\u64ad\u6548\u679c\uff0c\u5374\u591a\u6b21\u78b0\u58c1\uff0c\u8bf7\u6307\u6559\u95ee\u9898\u6240\u5728\u3002 \u6548\u679c\u5c55\u793a\uff1a \u539f\u6837\u5f0f \u81ea\u5b9e\u73b0\u6548\u679c \u4ee3\u7801\uff1a &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; .slider { width: 700px; height: 400px; overflow: hidden; position: relative; } .slider-wrapper { width: 700px; height: 400px; position: relative; } .slider-wrapper img { width: 700px; height: 400px; position: absolute; top: 0; } .indicator { height: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-52534","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52534"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52534\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}