admin管理员组文章数量:1191306
I have this url http://localhost:8080/?london and it needs to load to the id of london in <section id="london">.
- which is on the page.
I cannot use http://localhost:8080/#london, even though that will work!
To make things more complicated I am using a vue framework and they want the code inside master-origin/src/assets/js/mixins/Anchor.js - therefore I can't install jquery, has to be vanilla js.
I have tried
var el = [];
el = window.location.href.split("/?")[1];
console.log("el: " + el);
el.scrollIntoView();
Which grabs the value after the /?, but I when I tried to scrollIntoView, I get this message in the console
TypeError: el.scrollIntoView is not a function at VM10022 IE work:4
Why? I am following w3 schools guide .asp
I have this url http://localhost:8080/?london and it needs to load to the id of london in <section id="london">.
- which is on the page.
I cannot use http://localhost:8080/#london, even though that will work!
To make things more complicated I am using a vue framework and they want the code inside master-origin/src/assets/js/mixins/Anchor.js - therefore I can't install jquery, has to be vanilla js.
I have tried
var el = [];
el = window.location.href.split("/?")[1];
console.log("el: " + el);
el.scrollIntoView();
Which grabs the value after the /?, but I when I tried to scrollIntoView, I get this message in the console
TypeError: el.scrollIntoView is not a function at VM10022 IE work:4
Why? I am following w3 schools guide https://www.w3schools.com/jsref/met_element_scrollintoview.asp
Share Improve this question asked Nov 17, 2018 at 14:25 artworkjpmartworkjpm 1,3372 gold badges21 silver badges49 bronze badges3 Answers
Reset to default 17You try to call .scrollIntoView()
on a string.
Try this: document.getElementById(el).scrollIntoView();
Works great for me
const el = document.getElementById('item');
el.scrollIntoView({behavior: "smooth"});
window.scrollTo({
top: document.getElementById("allCars").offsetTop,
left: 0,
behavior: "smooth",
});
本文标签: javascriptscroll to id element when using quotquot in urlvuejsStack Overflow
版权声明:本文标题:javascript - scroll to id element when using "?" in url, vue.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738446662a2087253.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论