如何在两个页面中使用Javascript滚动到特定div
我有一个比较按钮,它出现在我的项目的两个不同页面中。当我点击它时,它调用一个javascript函数。我想编辑此函数,以便它执行以下操作:首先确定我所在的页面,然后向上滚动到此页面中的某个DIV 以下是函数:如何在两个页面中使用Javascript滚动到特定div,javascript,Javascript,我有一个比较按钮,它出现在我的项目的两个不同页面中。当我点击它时,它调用一个javascript函数。我想编辑此函数,以便它执行以下操作:首先确定我所在的页面,然后向上滚动到此页面中的某个DIV 以下是函数: $(function() { $('.cont_fontsicon').click(function compareProduct(event) { event.preventDefault(); var currentId = $(this).attr('id');
$(function() {
$('.cont_fontsicon').click(function compareProduct(event) {
event.preventDefault();
var currentId = $(this).attr('id');
console.log("currentId : "+currentId)
if(currentId.search("#") > 0){
var span= $(this).find('span.icon-copy_icon.icon_circle_base.icon_gray_878881.bord_rad30.selected');
if ($(this).find('span').is('.selected')){
return false;
evt.preventDefault();
}
var valueSplit=currentId.split('+#+');
var currentIdCat=valueSplit[0];
var currentIdStr=valueSplit[1];
var currentPrdType=valueSplit[2];
var resultClassName = $("#prodBoxId"+currentIdStr).attr('class');
var catId = document.getElementById("category_list").value;
var catIdStr = catId.trim();
var listSize = document.getElementById("productlistSize").value;
var comparisonProductType = document.getElementById("productType").value;
var catEndecaId=currentIdCat;
var catEndecaIdStr = catEndecaId.trim();
var userHead=document.getElementById("userHeader").value;
var errorMessagesValue=document.getElementById("errorMessagesContainer").value;
if(catIdStr == 0){
addProductToComparisonList(currentIdStr,$(this),listSize);
}
/*To be uncommented if we get more than one type of product for one category
*
* if(catIdStr == catEndecaIdStr && currentPrdType==comparisonProductType){ */
else if(catIdStr == catEndecaIdStr ){
if(userHead.search("Android")>0 || userHead.search("Mobi")>0)
{ if(listSize<2 ){
addProductToComparisonList(currentIdStr,$(this),listSize);
}
else
{
$("#prodBoxId"+currentIdStr).append('<div class="error_message"><div class="cont_img_alert inline_block"></div><span class="text_error_message inline_block">'+errorMessagesValue.compare2Products+'</span></div>');
var divPosition = $('#prodBoxId'+currentIdStr+' .error_message').offset();
$('html, body').animate({scrollTop: divPosition.top}, "fast");
}
}
else
{
if(listSize<3){
addProductToComparisonList(currentIdStr,$(this),listSize);
}
else
$("#prodBoxId"+currentIdStr).append('<div class="error_message"><div class="cont_img_alert inline_block"></div><span class="text_error_message inline_block">'+errorMessagesValue.compare3Products+'</span></div>');
var divPosition = $('#prodBoxId'+currentIdStr+' .error_message').offset();
$('html, body').animate({scrollTop: divPosition.top}, "fast");
}
}
//Fix for defect# 1660
if(catIdStr != 0 && catIdStr != catEndecaIdStr ){
$("#prodBoxId"+currentIdStr).append('<div class="error_message"><div class="cont_img_alert inline_block"></div><span class="text_error_message inline_block">'+errorMessagesValue.compareSameCategory+'</span></div>');
var divPosition = $('#prodBoxId'+currentIdStr+' .error_message').offset();
$('html, body').animate({scrollTop: divPosition.top}, "fast");
}
}
else {
var loggedInUser = document.getElementById("checkLoggedIn").value;
if(loggedInUser == 'true')
{
document.getElementById(currentId).href = '#';
/*showPopUp("wishlist",currentId);*/
$(this).closest('div').find('a#customPopup').trigger("click");
}
else
{
document.getElementById(currentId).submit();
}
}
});
$(函数(){
$('.cont_fontsicon')。单击(函数比较产品(事件){
event.preventDefault();
var currentId=$(this.attr('id');
console.log(“currentId:+currentId”)
如果(currentId.search(“#”)大于0{
var span=$(this.find('span.icon-copy_icon.icon_circle_base.icon_gray_878881.bord_rad30.selected');
如果($(this).find('span')。是('.selected')){
返回false;
evt.preventDefault();
}
var valueSplit=currentId.split('+#+');
var currentIdCat=valueSplit[0];
var currentIdStr=valueSplit[1];
var currentPrdType=valueSplit[2];
var resultClassName=$(“#prodBoxId”+currentIdStr).attr('class');
var catId=document.getElementById(“类别列表”).value;
var catIdStr=catId.trim();
var listSize=document.getElementById(“productlistSize”).value;
var comparisonProductType=document.getElementById(“productType”).value;
var catEndecaId=currentIdCat;
var catEndecaIdStr=catEndecaId.trim();
var userHead=document.getElementById(“userHeader”).value;
var errorMessagesValue=document.getElementById(“errorMessagesContainer”).value;
如果(catIdStr==0){
addProductToComparisonList(currentIdStr,$(this),listSize);
}
/*如果我们为一个类别获得多个产品类型,则取消注释
*
*如果(catIdStr==catEndecaIdStr&¤tPrdType==comparisonProductType){*/
否则如果(catIdStr==catEndecaIdStr){
if(userHead.search(“Android”)>0 | | userHead.search(“Mobi”)>0)
{if(listSize)