这里是StackOverflow的新手,所以如果有任何我需要做的事情,请告诉我。
我在我的网站(https://github.com/cferdinandi/smooth-scroll)上使用了cferdinanadi的平滑滚动插件,但是我想在点击链接后删除我网址中的锚点链接。所以现在当我点击一个链接时,我的网址就变成了(www.mysite.com/#anchor),但我希望它保持为(www.mysite.com)
在提供的文档(https://github.com/cferdinandi/smooth-scroll)的最底部,我找到了应该从URL中删除这些锚链接的辅助函数,但我不确定应该在哪里粘贴代码以使其工作
任何人都可以帮助我吗?这里提供的代码应该修复它:
var scroll = new SmoothScroll();
var smoothScrollWithoutHash = function (selector, settings) {
/**
* If smooth scroll element clicked, animate scroll
*/
var clickHandler = function (event) {
var toggle = event.target.closest( selector );
console.log(toggle);
if ( !toggle || toggle.tagName.toLowerCase() !== 'a' ) return;
console.log(toggle.hash);
var anchor = document.querySelector( toggle.hash );
if ( !anchor ) return;
event.preventDefault(); // Prevent default click event
scroll.animateScroll( anchor, toggle, settings || {} ); // Animate scroll
};
window.addEventListener('click', clickHandler, false );
};
// Run our function
smoothScrollWithoutHash( 'a[href*="#"]' );
答案 0 :(得分:0)
好的,我最终只是使用了一种解决方法。
对于任何想要解决这个问题的人,只需添加:
Sub xmlPerRow()
sTemplateXML = _
"<?xml version='1.0'?>" + vbNewLine + "<data>" + vbNewLine + "<Grai>" + vbNewLine + "</Grai>" + vbNewLine + _
" <DayDateOut>" + vbNewLine + " </DayDateOut>" + vbNewLine + " <Filler>" + vbNewLine + " </Filler>" + vbNewLine + _
" <FillerCountry>" + vbNewLine + " </FillerCountry>" + vbNewLine + " <Retailer>" + vbNewLine + " </Retailer>" + vbNewLine + _
" <RetailerCountry>" + vbNewLine + " </RetailerCountry>" + vbNewLine + " <Days>" + vbNewLine + " </Days>" + vbNewLine + _
" <DayBack>" + vbNewLine + " </DayBack>" + vbNewLine + " <DateIn>" + vbNewLine + " </DateIn>" + vbNewLine + _
" <BrokenCode>" + vbNewLine + " </BrokenCode>" + vbNewLine + " <Broken>" + vbNewLine + " </Broken>" + vbNewLine + _
" <TotalCycles>" + vbNewLine + " </TotalCycles>" + vbNewLine + "</data>" + vbNewLine
Set doc = CreateObject("MSXML2.DOMDocument")
doc.async = False
doc.validateOnParse = False
doc.resolveExternals = False
With ActiveWorkbook.Worksheets(1)
lLastRow = .UsedRange.Rows.Count
For lRow = 2 To lLastRow
sFile = "Grai_" & .Cells(lRow, 1).Value & ".xml"
Dim sGrai As String
sGrai = CStr(.Cells(lRow, 1).Value)
sDayDateOut = .Cells(lRow, 2).Value
sFiller = .Cells(lRow, 3).Value
sFillerCountry = .Cells(lRow, 4).Value
sRetailer = .Cells(lRow, 5).Value
sRetailerCountry = .Cells(lRow, 6).Value
sDays = .Cells(lRow, 7).Value
sDayBack = .Cells(lRow, 8).Value
sDateIn = .Cells(lRow, 9).Value
sBrokenCode = .Cells(lRow, 10).Value
sBroken = .Cells(lRow, 11).Value
sTotalCycles = .Cells(lRow, 12).Value
doc.LoadXML sTemplateXML
doc.getElementsByTagName("Grai")(0).appendChild doc.createTextNode(sGrai)
doc.getElementsByTagName("DayDateOut")(0).appendChild doc.createTextNode(sDayDateOut)
doc.getElementsByTagName("Filler")(0).appendChild doc.createTextNode(sFiller)
doc.getElementsByTagName("RetailerCountry")(0).appendChild doc.createTextNode(sRetailerCountry)
doc.getElementsByTagName("Retailer")(0).appendChild doc.createTextNode(sRetailer)
doc.getElementsByTagName("Days")(0).appendChild doc.createTextNode(sDays)
doc.getElementsByTagName("DayBack")(0).appendChild doc.createTextNode(sDayBack)
doc.getElementsByTagName("DateIn")(0).appendChild doc.createTextNode(sDateIn)
doc.getElementsByTagName("BrokenCode")(0).appendChild doc.createTextNode(sBrokenCode)
doc.getElementsByTagName("Broken")(0).appendChild doc.createTextNode(sBroken)
doc.getElementsByTagName("TotalCycles")(0).appendChild doc.createTextNode(sTotalCycles)
doc.Save sFile
Next
End With
End Sub
到.js文件的底部。