我正在Phone Gap-android中做一个项目。我正在java脚本中实现功能。我已经使用它实现了SWIPE VIEW 。
现在,我将分享我用来实现此功能的编码,以帮助您找出我的错误。
var mySwiper = new Swiper('.swiper-container',{
//Your options here:
mode:'horizontal',loop: true, speed : 500, freeMode : true, freeModeFluid : true,
});
value= VALUE_FROM_DB.split("||");
for (k=0;k<value.length;k++)
{
if (value[0] == paramName1)
{
return unescape(value[k]);
console.log("no of swipe views ");
}
var val = k+1;
var superdiv = document.getElementById('swiper-wrapper');
var newdiv = document.createElement('div');
var divIdName = 'swiper-slide'+val;
console.log("div name: "+divIdName);
newdiv.setAttribute('id',divIdName);
newdiv.setAttribute('class','swiper-slide');
newdiv.style.width = "25%";
newdiv.style.height = "30%";
superdiv.appendChild(newdiv);
var cnt1 = '<div id="container" class="container"><span><img src="img/cause_'+val+'.png" style="float:left;"></span><div id="clinicals'+val+'" class="clinical"><span ><h5>'+value[k]+'</h5></span></div></div>';
console.log("check value"+cnt1);
document.getElementById(divIdName).innerHTML=cnt1;
console.log("clinical values: "+value[k]);
console.log("processsing parameter loop ");
var searchString = window.location.search.substring(1),i,val,params = searchString.split("&");
}
html代码
<div id="swipe_body">
<div class="swiper-container swiper-threshold">
<div class="swiper-wrapper" id="swiper-wrapper">
</div>
</div>
</div>
CSS代码:
.clinical
{
font-size:15px;text-justify:inter-word;margin-right:10px; margin-left:10px; margin-top:10px; margin-right:10px; margin-bottom:10px;
}
.container
{
background:url(img/value_bg.png) no-repeat scroll 0 0 transparent; background-size:100% 100%; display:block; width:304px; height:250px;text-align:justify;
}
.container span
{
width:auto; height:30%; display:block; overflow:hidden;float:left;
}
现在,我的输出不是想要的。
仅显示 1 张幻灯片。未实现滑动功能,其余其他值均不可见。
我应该怎么办?请指导我!
第二种选择,我实现如下(在没有滑动视图之后):
var val = k+1;
var superdiv = document.getElementById('swiper-wrapper');
var newdiv = document.createElement('div');
var divIdName = 'swiper-slide'+val;
console.log("div name: "+divIdName);
newdiv.setAttribute('id',divIdName);
newdiv.setAttribute('class','swiper-slide');
superdiv.appendChild(newdiv);
---> var cnt1 ="var newSlide = mySwiper.createSlide('<div id="container" class="container"><span><img src="img/cause_'+val+'.png" style="float:left/>;"></span><div id="clinicals'+val+'" class="clinical"><span ><h5>'+value[k]+'</h5></span></div></div>', 'swiper-slide', 'span');
document.getElementById(divIdName).innerHTML=cnt1;
document.querySelector('.swiper-slide');
console.log("split value: "+value[k]);
我得到的输出错误是
05-20 12:11:20.214: E/Web Console(6855): Uncaught SyntaxError: Unexpected identifier at file:///android_asset/www/clinical.html?var%20id=0:171 (the line differentiated with an arrow)
最重要的事实是,所有 5 个值都显示在日志中。但是,正在看到 1 个幻灯片。
简而言之,滑动功能不起作用。