{"id":8580,"date":"2019-04-20T00:43:58","date_gmt":"2019-04-19T16:43:58","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=8580"},"modified":"2025-06-12T15:20:35","modified_gmt":"2025-06-12T07:20:35","slug":"css-scroll-snap-event-element-detect","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2019\/04\/css-scroll-snap-event-element-detect\/","title":{"rendered":"CSS scroll-snap\u6eda\u52a8\u4e8b\u4ef6\u505c\u6b62\u53ca\u5143\u7d20\u4f4d\u7f6e\u68c0\u6d4b"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=8580\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=8580<\/a><br \/>\n\u672c\u6587\u53ef\u5168\u6587\u8f6c\u8f7d\uff0c\u4e2a\u4eba\u7f51\u7ad9\u65e0\u9700\u6388\u6743\uff0c\u4f46\u9700\u8981\u4fdd\u7559\u539f\u4f5c\u8005\u3001\u51fa\u5904\u4ee5\u53ca\u6587\u4e2d\u94fe\u63a5\uff0c\u4efb\u4f55\u7f51\u7ad9\u5747\u53ef\u6458\u8981\u805a\u5408\uff0c\u5546\u7528\u8bf7\u8054\u7cfb\u6388\u6743\u3002<br \/>\n<script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/201904-scroll-snap.png';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201811\/scroll-snap.png\" width=\"484\" height=\"300\" alt=\"scroll snap\u4e0e\u6eda\u52a8\u4e8b\u4ef6\u7ed3\u675f\u68c0\u6d4b\" class=\"alignright clip size-medium\"><\/p>\n<p><strong>\u66f4\u65b0\u4e8e2025\u5e746\u670812\u65e5<\/strong><\/p>\n<p>\u73b0\u5728Web\u6d4f\u89c8\u5668\u539f\u751f\u652f\u6301\u4e86scrollend\u4e8b\u4ef6\uff0c\u76ee\u524d\u9664\u4e86Safari\u4ee5\u5916\uff0c\u90fd\u5df2\u7ecf\u652f\u6301\u4e86\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202506\/2025-06-12_151633.png\" width=\"629\" height=\"235\" alt=\"scrollend\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<h3>\u4e00\u3001Scroll Snap\u662f\u524d\u7aef\u5fc5\u5907\u6280\u80fd<\/h3>\n<p>CSS Scroll Snap\u662f\u4e2a\u975e\u5e38\u597d\u7528\u7684\u7279\u6027\uff0c\u53ef\u4ee5\u8ba9\u7f51\u9875\u5bb9\u5668\u6eda\u52a8\u505c\u6b62\u7684\u65f6\u5019\uff0c\u65e0\u9700\u4efb\u4f55JS\u4ee3\u7801\u7684\u53c2\u4e0e\uff0c\u6d4f\u89c8\u5668\u53ef\u4ee5\u81ea\u52a8\u5e73\u6ed1\u5b9a\u4f4d\u5230\u6307\u5b9a\u5143\u7d20\u7684\u6307\u5b9a\u4f4d\u7f6e\u3002\u7c7b\u4f3c\u5e7b\u706f\u7247\u5e7f\u544a\u6548\u679c\u5c31\u53ef\u4ee5\u7eafCSS\u5b9e\u73b0\u3002<\/p>\n<p>\u800c\u4e14CSS Scroll Snap\u7684\u517c\u5bb9\u6027\u975e\u5e38\u597d\uff0c\u79fb\u52a8\u7aef\u51e0\u4e4e\u53ef\u4ee5\u653e\u5fc3\u4f7f\u7528\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201904\/2019-04-19_225315.png\" width=\"560\" height=\"201\" alt=\"scroll-snap\u517c\u5bb9\u6027 \" class=\"alignnone size-medium\" \/><\/p>\n<p>\u66f4\u591a\u5173\u4e8eCSS Scroll Snap\u7684\u5185\u5bb9\u53ef\u4ee5\u53c2\u89c1\u6211\u4e4b\u524d\u7684\u6587\u7ae0\uff1a\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2018\/11\/know-css-scroll-snap\/\">\u5927\u4fa0\uff0c\u8981\u4e0d\u8fc7\u6765\u4e86\u89e3\u4e0bCSS Scroll Snap\uff1f<\/a>\u201d\uff0c\u5bf9\u76f8\u5173\u7684CSS\u5c5e\u6027\u6709\u8be6\u7ec6\u7684\u4ecb\u7ecd\u3002<\/p>\n<h3>\u4e8c\u3001\u6e90\u81ea\u5b9e\u9645\u9879\u76ee\u7684scroll-snap\u573a\u666f<\/h3>\n<p>\u4eca\u5929\u4e0b\u5348\u5728\u5b9e\u73b0\u4e00\u4e2a\u529f\u80fd\u9700\u6c42\u7684\u65f6\u5019\uff0c\u6b63\u597d\u9047\u5230\u4e00\u4e2a\u573a\u666f\u975e\u5e38\u9002\u5408\u4f7f\u7528Scroll Snap\u6765\u5b9e\u73b0\uff0c\u6ed1\u52a8\u4f9d\u6b21\u663e\u793a\u4eba\u7269\u89d2\u8272\u3002\u4e8e\u662f\u5c31\u5927\u80c6\u4f7f\u7528\u4e86\u4e0b\uff0c\u54c7\uff0c\u597d\u68d2\uff0c\u65e0\u9700\u4efb\u4f55js\u505a\u8fb9\u754c\u5224\u65ad\uff0c\u6ed1\u52a8\u505c\u6b62\u81ea\u52a8\u5b9a\u4f4d\u5230\u60f3\u8981\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u5173\u952eCSS\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>ul {\r\n    width: 375px; height: 667px;\r\n    <span style=\"color:#cd0000;\">scroll-snap-type: x mandatory;\r\n    -webkit-overflow-scrolling: touch;<\/span>\r\n    white-space: nowrap;\r\n    overflow-y: hidden;    \r\n}\r\nli {\r\n    display: inline-block;\r\n    width: 100%; height: 100%;\r\n    <span style=\"color:#cd0000;\">scroll-snap-align: center;<\/span>\r\n}<\/pre>\n<p>\u6eda\u52a8\u7236\u5bb9\u5668\u5143\u7d20\u8bbe\u7f6e<code>scroll-snap-type:x mandatory<\/code>\uff0c\u6c34\u5e73\u6eda\u52a8\uff0c\u5f3a\u5236\u5b9a\u4f4d\uff0c\u5b50\u5217\u8868\u5143\u7d20\u8bbe\u7f6e<code>scroll-snap-align:center<\/code>\u8ba9\u5217\u8868\u5728\u6eda\u52a8\u5bb9\u5668\u7684\u4e2d\u95f4\u663e\u793a\uff0c\u4e8e\u662f\u6548\u679c\u8fbe\u6210\u3002<\/p>\n<p>\u7136\u800c\uff0c\u6eda\u52a8\u5b9a\u4f4d\u7ed3\u675f\u540e\uff0c\u8fd8\u9700\u8981\u9700\u8981\u9ad8\u4eae\u5f53\u524d\u5b9a\u4f4d\u7684\u4eba\u7269\u7d20\u6750\u3002\u6211\u53d1\u73b0\u6709\u4e9b\u96be\u529e\u4e86\uff01<img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/1f914.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"> \u4ee5\u524d\u8fd9\u79cd\u6ed1\u52a8\u6548\u679c\u7528JS\u5b9e\u73b0\uff0c\u65e0\u8bba\u662fJS\u52a8\u753b\u7ed3\u675f\uff0c\u8fd8\u662fCSS\u52a8\u753b\u7ed3\u675f\uff0c\u90fd\u662f\u6709\u56de\u8c03\u51fd\u6570\u53ef\u4ee5\u4f7f\u7528\u7684\u3002\u4f46\u662f\u8fd9\u91cc\u5374\u662f\u6eda\u52a8\uff0c\u800c\u4e14\u6eda\u52a8\u540e\u8fd8\u4f1a\u81ea\u5df1\u518d\u5b9a\u4f4d\u4e00\u4f1a\u513f\uff0c\u81ea\u5df1\u5b9a\u4f4d\u65f6\u95f4\u6709\u957f\u6709\u77ed\uff0c\u8c01\u77e5\u9053\u4ec0\u4e48\u65f6\u5019\u505c\u6b62\uff1f\u6709\u65f6\u5019\u4e00\u53e3\u6c14\u6ed1\u591a\u4e2a\u5143\u7d20\uff0c\u4e5f\u4e0d\u786e\u5b9a\u5230\u5e95\u505c\u6b62\u5728\u54ea\u4e2a\u5143\u7d20\u4e0a\u3002<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0c\u6807\u51c6\u5236\u5b9a\u8005\u4eec\u548c\u6d4f\u89c8\u5668\u5382\u5546\u6b63\u5728\u79ef\u6781\u63a8\u8fdbScroll Snap\u76f8\u5173\u56de\u8c03\u4e8b\u4ef6\u7684\u843d\u5730\uff0c\u8fd9\u6837\u53ef\u4ee5\u7cbe\u786e\u77e5\u9053\u6eda\u5230\u4ec0\u4e48\u65f6\u5019\u505c\u6b62\u4ee5\u53ca\u6eda\u52a8\u5b9a\u4f4d\u5230\u54ea\u4e2a\u5143\u7d20\u4e0a\uff0c\u4f46\u662f\uff0c\u6807\u51c6\u8fd8\u5728\u6298\u817e\uff0c\u6d4f\u89c8\u5668\u8fd8\u6ca1\u6709\u652f\u6301\u3002\u9879\u76ee\u73b0\u5728\u5c31\u8981\u7528\uff0c\u600e\u4e48\u529e\u5462\uff1f<\/p>\n<p>\u5bf9\uff01\u80af\u5b9a\u8981\u51fa\u52a8JS\u8f85\u52a9\u3002<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0c\u5c31\u7b97\u4e0d\u662fScroll Snap\u7684\u4f7f\u7528\u573a\u666f\uff0c\u5c31\u7b97\u662f\u666e\u901a\u7684\u6eda\u52a8\uff0c\u7531\u4e8e\u6eda\u52a8\u5177\u6709\u60ef\u6027\uff0c\u68c0\u6d4b\u6eda\u52a8\u662f\u5426\u505c\u6b62\u4e5f\u662f\u4e00\u4e2a\u7ecf\u5e38\u4f1a\u9047\u5230\u7684\u9700\u6c42\u3002\u56e0\u6b64\uff0c\u6709\u5fc5\u8981\u634b\u4e00\u4e2a\u68c0\u6d4b\u6eda\u52a8\u4ec0\u4e48\u65f6\u5019\u505c\u6b62\u7684\u65b9\u6cd5\u3002<\/p>\n<h3>\u4e09\u3001\u6211\u7684\u6eda\u52a8\u4e2d\u6b62\u68c0\u6d4b\u65b9\u6cd5<\/h3>\n<p>\u68c0\u6d4b\u5143\u7d20\u7684\u6eda\u52a8\u662f\u5426\u505c\u6b62\uff0c\u6211\u7684\u5b9e\u73b0\u601d\u8def\u662f\u8fd9\u6837\u7684\uff0c\u5728\u6eda\u52a8\u4e8b\u4ef6\u4e2d\u8dd1\u4e00\u4e2a\u5b9a\u65f6\u5668\uff0c\u8bb0\u5f55\u5f53\u524d\u65f6\u95f4\u7684\u6eda\u52a8\u8ddd\u79bb\u548c\u4e0a\u4e00\u6b21\u6eda\u52a8\u7684\u8ddd\u79bb\u662f\u5426\u76f8\u7b49\uff0c\u5982\u679c\u76f8\u7b49\u5219\u8ba4\u4e3a\u6eda\u52a8\u5df2\u7ecf\u505c\u6b62\uff0c\u5982\u679c\u4e0d\u76f8\u7b49\uff0c\u5219\u8ba4\u4e3a\u6eda\u52a8\u4f9d\u7136\u5728\u8fdb\u884c\u3002<\/p>\n<p>\u7528JavaScript\u793a\u610f\u5c31\u662f\uff08<strong>\u8fd9\u4e2a\u5b9e\u73b0\u5df2\u4f5c\u5e9f<\/strong>\uff09\uff1a<\/p>\n<pre style=\"opacity:.75;filter:grayscale(1);\"><span style=\"color:green;\">\/\/ \u5b9a\u65f6\u5668\uff0c\u7528\u6765\u68c0\u6d4b\u6c34\u5e73\u6eda\u52a8\u662f\u5426\u7ed3\u675f<\/span>\r\nvar timer = null;\r\n<span style=\"color:green;\">\/\/ \u4e0a\u4e00\u6b21\u6eda\u52a8\u7684\u8ddd\u79bb<\/span>\r\nvar scrollLeft = 0, scrollTop = 0;\r\n<span style=\"color:green;\">\/\/ \u6eda\u52a8\u4e8b\u4ef6\u5f00\u59cb<\/span>\r\ncontainer.addEventListener('scroll', function () {\r\n    clearInterval(timer);\r\n    <span style=\"color:green;\">\/\/ \u91cd\u65b0\u65b0\u7684\u5b9a\u65f6\u5668<\/span>\r\n    timer = setInterval(function () {\r\n        if (container.scrollLeft == scrollLeft &amp;&amp; container.scrollTop == scrollTop) {\r\n            <span style=\"color:green;\">\/\/ \u6eda\u52a8\u8ddd\u79bb\u76f8\u7b49\uff0c\u8ba4\u4e3a\u505c\u6b62\u6eda\u52a8\u4e86<\/span>\r\n            clearInterval(timer);\r\n            <span style=\"color:green;\">\/\/ ... \u505a\u4f60\u60f3\u505a\u7684\u4e8b\u60c5\uff0c\u5982\u56de\u8c03\u5904\u7406<\/span>\r\n        } else {\r\n            <span style=\"color:green;\">\/\/ \u5426\u5219\uff0c\u4f9d\u7136\u8bb0\u4f4f\u4e0a\u4e00\u6b21\u6eda\u52a8\u4f4d\u7f6e<\/span>\r\n            scrollLeft = container.scrollLeft;\r\n            scrollTop = container.scrollTop;\r\n        }\r\n    }, 100);\r\n});<\/pre>\n<p>\u5982\u679c\u4f60\u6709\u5174\u8da3\uff0c\u53ef\u4ee5\u5bf9\u4e0a\u9762\u4ee3\u7801\u8fdb\u884c\u8fdb\u4e00\u6b65\u5c01\u88c5\u3002<\/p>\n<p><strong>\u66f4\u65b0\u4e8e\u7fcc\u65e5<\/strong><\/p>\n<p>\u6eda\u52a8\u7ec8\u6b62\u68c0\u6d4b\u53ef\u4ee5\u65e0\u9700\u5224\u65ad\u524d\u540e\u6eda\u52a8\u8ddd\u79bb\u662f\u5426\u76f8\u7b49\uff0c\u56e0\u4e3a\u65e0\u8bba\u662f\u60ef\u6027\u8fd8\u662fSnap\u5b9a\u4f4dscroll\u4e8b\u4ef6\u4e5f\u662f\u6301\u7eed\u89e6\u53d1\u7684\u3002\u56e0\u6b64\uff0c\u53ef\u4ee5\u76f4\u63a5\u8fd9\u6837\uff1a<\/p>\n<pre><span style=\"color:green;\">\/\/ \u5b9a\u65f6\u5668\uff0c\u7528\u6765\u68c0\u6d4b\u6c34\u5e73\u6eda\u52a8\u662f\u5426\u7ed3\u675f<\/span>\r\nvar timer = null;\r\n<span style=\"color:green;\">\/\/ \u6eda\u52a8\u4e8b\u4ef6\u5f00\u59cb<\/span>\r\ncontainer.addEventListener('scroll', function () {\r\n    clearTimeout(timer);\r\n    <span style=\"color:green;\">\/\/ \u91cd\u65b0\u65b0\u7684\u5b9a\u65f6\u5668<\/span>\r\n    timer = setTimeout(function () {\r\n        <span style=\"color:green;\">\/\/ \u65e0\u6eda\u52a8\u4e8b\u4ef6\u89e6\u53d1\uff0c\u8ba4\u4e3a\u505c\u6b62\u6eda\u52a8\u4e86<\/span>\r\n        <span style=\"color:green;\">\/\/ ... \u505a\u4f60\u60f3\u505a\u7684\u4e8b\u60c5\uff0c\u5982\u56de\u8c03\u5904\u7406<\/span>\r\n    }, 100);\r\n});<\/pre>\n<p>\u5f53\u7136\uff0c\u4e0a\u9762\u63d0\u4f9b\u7684\u65b9\u6cd5\u5e76\u4e0d\u662f\u975e\u5e38\u7cbe\u51c6\u7684\u4e2d\u6b62\u68c0\u6d4b\uff0c\u56e0\u4e3aScroll Snap\u6700\u540e\u7684\u91cd\u5b9a\u4f4d\u6d4f\u89c8\u5668\u81ea\u8eab\u6709\u4e2a\u68c0\u6d4b\uff0c\u8fd9\u4e2a\u68c0\u6d4b\u4e8b\u4ef6\uff0c\u6839\u636e\u6211\u7684\u53cd\u590d\u7814\u7a76\u4e0e\u6d4b\u8bd5\uff0c\u5e94\u8be5\u662f<strong>350ms<\/strong>\uff08\u5b9e\u9645\u8fd0\u884c\u53ef\u80fd\u4f1a\u7565\u5fae\u5927\u51e0\u6beb\u79d2\uff09\uff0c\u8fdc\u6bd4\u4e0a\u9762\u8bbe\u7f6e\u7684<code>100ms<\/code>\u8981\u5927\uff0c\u56e0\u6b64\uff0c\u4f1a\u6709\u4e00\u6b21\u9519\u8bef\u7684\u5197\u4f59\u5224\u65ad\uff0c\u53d1\u751f\u5728Snap\u5b9a\u4f4d\u5f00\u59cb\u4e4b\u524d\u3002<\/p>\n<p>\u6211\u60f3\u4e86\u60f3\uff0c\u8fd9\u4e2a\u95ee\u9898\u65e0\u6cd5\u907f\u514d\uff0c\u4f46\u4e5f\u4e0d\u662f\u4ec0\u4e48\u5927\u95ee\u9898\u3002\u603b\u4e0d\u53ef\u80fd\u8bbe\u7f6e<code>400ms<\/code>\u68c0\u6d4b\uff0c\u5ef6\u8fdf\u592a\u9ad8\uff0c\u4f53\u9a8c\u4e0d\u4e00\u5b9a\u597d\u3002<\/p>\n<h3>\u56db\u3001\u5f53\u524d\u6eda\u52a8\u76ee\u6807\u5143\u7d20\u68c0\u6d4b\u65b9\u6cd5<\/h3>\n<p>\u539f\u7406\u5982\u4e0b\uff0c\u904d\u5386\u6240\u6709\u7684\u5217\u8868\u5143\u7d20\uff0c\u68c0\u6d4b\u5217\u8868\u5143\u7d20\u7684\u5de6\u8fb9\u7f18\u76f8\u5bf9\u4e8e\u6eda\u52a8\u5bb9\u5668\u5de6\u8fb9\u7f18\uff08\u5982\u679c\u662f\u5de6\u5bf9\u9f50-<code>scroll-snap-align:left<\/code>\uff09\u6216\u4e2d\u5fc3\uff08\u5c45\u4e2d\u5bf9\u9f50\uff09\u6216\u53f3\u8fb9\u7f18\uff08\u53f3\u5bf9\u9f50\uff09\u7684\u4f4d\u7f6e\u3002\u5f53\u7136\uff0c\u5982\u679c\u5217\u8868\u5143\u7d20\u5c3a\u5bf8\u548c\u6eda\u52a8\u5bb9\u5668\u5c3a\u5bf8\u4e00\u81f4\uff0c\u5219\u5de6\u4e2d\u53f3\u8fb9\u7f18\u68c0\u6d4b\u90fd\u53ef\u4ee5\u3002<\/p>\n<p>JS\u793a\u610f\uff1a<\/p>\n<pre>[].slice.call(container.children).forEach(function (ele, index) {\r\n    if (Math.abs(ele.getBoundingClientRect().left - container.getBoundingClientRect().left) &lt; 10) {\r\n        <span style=\"color:green;\">\/\/ \u6b64\u523b\u7684ele\u5143\u7d20\u5c31\u662f\u5f53\u524d\u5b9a\u4f4d\u7684\u5143\u7d20\r\n        \/\/ ... \u4f60\u53ef\u4ee5\u5bf9ele\u505a\u4f60\u60f3\u505a\u7684\u4e8b\u60c5<\/span>\r\n    } else {\r\n        <span style=\"color:green;\">\/\/ \u6b64\u523b\u7684ele\u5143\u7d20\u4e0d\u662f\u5f53\u524d\u5b9a\u4f4d\u7684\u5143\u7d20<\/span>\r\n    }\r\n});<\/pre>\n<p>\u4e25\u683c\u6765\u8bb2\uff0c\u5e94\u8be5\u8ba1\u7b97\u662f\u5426\u7b49\u4e8e<code>0<\/code>\uff0c\u800c\u4e0d\u662f\u5c0f\u4e8e<code>10<\/code>\uff0c\u8fd9\u91cc\u561b\uff0c\u52a0\u4e86\u70b9\u5bb9\u9519\u533a\u95f4\u5427\u3002<\/p>\n<p>\u641e\u5b9a\u4e86\u4e0a\u97622\u4e2a\u9700\u8981JS\u8f85\u52a9\u7684\u9700\u6c42\u70b9\uff0c\u6700\u7ec8\u7684\u6548\u679c\u5c31\u51fa\u6765\u4e86\u3002<\/p>\n<h3>\u4e94\u3001\u6700\u7ec8\u5b9e\u73b0\u7684\u6548\u679c\u5c55\u793a<\/h3>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/201904\/scroll-snap-end-event-detect-demo.php\" target=\"_blank\" rel=\"noopener\">CSS scroll-snap\u6eda\u52a8\u4e8b\u4ef6\u7ed3\u675f\u5224\u65addemo<\/a><\/p>\n<p>\u6b64demo\u66f4\u9002\u5408\u624b\u673a\u7aef\u8bbf\u95ee\uff0c\u6545\u9644\u4e0a\u4e8c\u7ef4\u7801\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201904\/2019-04-20_001215.png\" width=\"150\" height=\"150\" alt=\"\u6eda\u52a8\u505c\u6b62\u68c0\u6d4b\u4e8c\u7ef4\u7801\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u6700\u7ec8\u5b9e\u73b0\u6548\u679c\u5982\u4e0b\u89c6\u9891\u6240\u793a\uff08\u4e0d\u52a8\u8bf7\u70b9\u51fb\uff09\uff1a<\/p>\n<p><video src='\/\/image.zhangxinxu.com\/video\/blog\/201904\/scroll-snap.mp4' type=\"video\/mp4\" width=\"366\" height=\"574\" preload=\"auto\" autoplay autobuffer loop x-webkit-airplay=\"allow\" x5-video-player-type=\"h5\" x5-video-player-fullscreen=\"true\" x5-video-orientation=\"portraint\" webkit-playsinline=\"true\" playsinline=\"true\" \u200b\u200b\u200b\u200bposter=\"\/\/image.zhangxinxu.com\/image\/blog\/201806\/poster.png\"><\/video><\/p>\n<p>\u901a\u8fc7\u68c0\u6d4b\u6eda\u52a8\u7ed3\u675f\uff0c\u51c6\u786e\u9ad8\u4eae\u5f53\u524d\u5c55\u793a\u7684\u5143\u7d20\uff08\u901a\u8fc7CSS filter\u6ee4\u955c\u63a7\u5236\u5143\u7d20\u7684grayscale\u7070\u5ea6\uff09\u3002\u81f3\u4e8e\u6ed1\u52a8\u4e0e\u5b9a\u4f4d\u6548\u679c\uff0c\u5b8c\u5168\u4ea4\u7ed9CSS\u5b9e\u73b0\u3002\u6bd4\u4f20\u7edf\u4f7f\u7528\u7c7b\u4f3cSwipe.js\u5b9e\u73b0\u5207\u6362\u6548\u679c\u8981\u7b80\u5355\u5f88\u591a\uff0c\u6027\u80fd\u4e5f\u66f4\u597d\uff0c\u8d44\u6e90\u5360\u7528\u4e5f\u66f4\u5c11\u3002<\/p>\n<h3>\u516d\u3001\u7ed3\u675f\u8bed<\/h3>\n<p>\u6bd5\u7adf\u662fCSS\u65b0\u5c5e\u6027\uff0c\u4e00\u4e9b\u8001\u65e7\u7684Android\u624b\u673a\u517c\u5bb9\u4e0a\u786e\u5b9e\u6709\u70b9\u95ee\u9898\uff0c\u56e0\u4e3a\u8fd9\u6837\u7684\u539f\u56e0\uff0c\u5f88\u591a\u4eba\u671b\u800c\u5374\u6b65\uff0c\u4e0d\u6562\u4f7f\u7528\u8fd9\u4e9b\u4f18\u79c0\u7684\u7279\u6027\u3002<\/p>\n<p>\u5927\u53ef\u4e0d\u5fc5\uff0c\u4e0d\u80fd\u4e3a\u4e861%\u7684\u7cdf\u7c95\u727a\u727299%\u7684\u7cbe\u534e\u3002<\/p>\n<p>\u5bf9\u4e8e\u9648\u65e7\u8bbe\u5907\uff0c\u6211\u4eec\u53ef\u4ee5\u4e0d\u5fc5\u5b8c\u7f8e\u4e00\u81f4\u7684\u4f53\u9a8c\uff0c\u53ea\u8981\u4fdd\u8bc1\u529f\u80fd\u5b8c\u5168\u6b63\u5e38\u5c31\u53ef\u4ee5\uff0c\u7528\u6237\u5176\u5b9e\u4e0d\u5728\u610f\u7684\u3002\u8fd9\u4e00\u70b9\u4e0a\uff0c\u53ef\u4ee5\u597d\u597d\u548c\u5382\u5b50\u7684\u6d4b\u8bd5\u540c\u5b66\u6c9f\u901a\u6c9f\u901a\uff0c\u6ca1\u6709\u5fc5\u8981\u6240\u6709\u6d4f\u89c8\u5668\u90fd\u4e00\u6837\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u5bf9\u4e8e<code>scroll-snap-type<\/code>\u7b49\u5c5e\u6027\uff0c\u662f\u6709polyfill\u7684\uff0c\u5f15\u5165\u4e00\u4e2aJS\u5373\u53ef\u3002<\/p>\n<p>\u5982\u679cpolyfill\u4e5f\u6ca1\u7528\uff0c\u5927\u4e0d\u4e86\u505a\u4e2a\u7279\u5f81\u68c0\u6d4b\uff0c\u5982\u679c\u6d4f\u89c8\u5668\u4e0d\u652f\u6301<code>scroll-snap-type<\/code>\u7b49\u5c5e\u6027\uff0c\u90a3\u5c31\u8001\u8001\u5b9e\u5b9e\u4f7f\u7528<code>transform<\/code>\u4f4d\u79fb\u8fdb\u884c\u5b9a\u4f4d\uff0c\u6216\u8005\u4e13\u95e8\u518d\u53bb\u52a0\u8f7d\u4e2a\u7b2c\u4e09\u65b9JS\u5904\u7406\u3002<\/p>\n<p>\u8d8a\u6298\u817e\u8d8a\u6210\u957f\uff0c\u9002\u5f53\u7ed9\u81ea\u5df1\u7684\u9879\u76ee\u589e\u52a0\u70b9\u96be\u5ea6\uff0c\u591a\u4e00\u70b9\u8ffd\u6c42\uff0c\u6280\u672f\u6210\u957f\u5c31\u4f1a\u6bd4\u522b\u4eba\u66f4\u5feb\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/1f60f.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=8580\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=8580<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201811\/scroll-snap.png\" width=\"161\" height=\"100\" loading=lazy alt=\"scroll snap\u5934\u56fe\" class=\"alignright size-medium\"><\/p>\n<p>CSS Scroll Snap\u662f\u4e2a\u975e\u5e38\u597d\u7528\u7684\u7279\u6027\uff0c\u53ef\u4ee5\u8ba9\u6eda\u52a8\u505c\u6b62\u7684\u65f6\u5019\uff0c\u65e0\u9700\u4efb\u4f55JS\u4ee3\u7801\uff0c\u81ea\u52a8\u5e73\u6ed1\u5b9a\u4f4d\u5230\u6307\u5b9a\u5143\u7d20\u7684\u6307\u5b9a\u4f4d\u7f6e\u3002\u4f46\u5b9e\u9645\u5f00\u53d1\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u5f88\u591a\u573a\u666f\u8fd8\u9700\u8981\u77e5\u9053\u6eda\u52a8\u4ec0\u4e48\u65f6\u5019\u505c\u6b62\uff0c\u4ee5\u53ca\u5230\u5e95\u6eda\u52a8\u5230\u54ea\u4e2a\u5143\u7d20\u4e0a\uff0c\u6d4f\u89c8\u5668\u76ee\u524d\u8fd8\u6ca1\u6709\u539f\u751f\u7684\u65b9\u6cd5\u652f\u6301\uff0c\u9700\u8981\u6211\u4eec\u4f7f\u7528JS\u8fdb\u884c\u8f85\u52a9\u5904\u7406\u2026\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[180],"tags":[368,623,1360,1379,1378,632,124],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/8580"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=8580"}],"version-history":[{"count":2,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/8580\/revisions"}],"predecessor-version":[{"id":11741,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/8580\/revisions\/11741"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=8580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=8580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=8580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}