JS部分
 createSwiper1() {
var option = {
// slidesPerView: 5,
slidesPerView: 3,
centeredSlides:true,
};
if (this.state.newData.length > 2) {
option = {
loop: true,
loopedSlides: this.state.newData.length,
loopAdditionalSlides: 3,
slidesPerView: 'auto',
// slidesPerView: '3',
centeredSlides:true,
effect:'coverflow',
paginationClickable: true,
preventLinksPropagation: true,
observer: true,//修改swiper自己或子元素时,自动初始化swiper
observeParents: true,//修改swiper的父元素时,自动初始化swiper
coverflow:{
rotate: 0,
stretch: 85,
depth: 52,
modifier: 1,
slideShadows: true
}, nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
onTouchEnd: (swiper) => {
window.slideSwitchMp3();
}
}
}
var mySwiper = new Swiper('#'+ (this.props.place +'NewSwiperId'),option); mySwiper.on('tap',(swiper,e) => {
var that=this;
let item = this.state.newData[swiper.realIndex];
var buttonId=document.getElementById(this.props.place +'buttonId')
var buttonPrev=document.getElementById(this.props.place +'button-prev')
var buttonNext=document.getElementById(this.props.place +'button-next')
if(that.isDOMContains(buttonPrev,e.target,buttonId) ||that.isDOMContains2(buttonNext,e.target,buttonId)){
return false;
}else {
if (item) {
this.setState({newDetailShow: true, selectNewItem: item, eyeNum: 0, newDetailData: []}, () => {
if (item.infotype == 2) {
this.createPdf(item.pdfurl);
}
else {
this.fetchNewDetail();
}
this.props.parentCallback && this.props.parentCallback();
});
window.clickSoundEffect();
}
}
});
},

解决轮播按钮被覆盖
 isDOMContains:function(parentEle,ele,container){

     //判断一个节点是否是其子节点
//parentEle: 要判断节点的父级节点
//ele:要判断的子节点
//container : 二者的父级节点 //如果parentEle h和ele传的值一样,那么两个节点相同
if(parentEle == ele){
return true
}
if(!ele || !ele.nodeType || ele.nodeType != 1){
return false;
}
//如果浏览器支持contains
if(parentEle.contains){
return parentEle.contains(ele)
} //火狐支持
// if(parentEle.compareDocumentPosition){
// return !!(parentEle.compareDocumentPosition(ele)&16);
// } //获取ele的父节点
// var parEle = ele.parentNode;
// while(parEle && parEle != container){
// if(parEle == parentEle){
// return true;
// }
// parEle = parEle.parentNode;
// }
return false;
}, isDOMContains2:function(parentEle,ele,container){
console.log("parentEle",parentEle)
console.log("container",container)
//判断一个节点是否是其子节点
//parentEle: 要判断节点的父级节点
//ele:要判断的子节点
//container : 二者的父级节点 //如果parentEle h和ele传的值一样,那么两个节点相同
if(parentEle == ele){
return true
}
if(!ele || !ele.nodeType || ele.nodeType != 1){
return false;
}
//如果浏览器支持contains
if(parentEle.contains){
return parentEle.contains(ele)
} //火狐支持
// if(parentEle.compareDocumentPosition){
// return !!(parentEle.compareDocumentPosition(ele)&16);
// } //获取ele的父节点
// var parEle = ele.parentNode;
// while(parEle && parEle != container){
// if(parEle == parentEle){
// return true;
// }
// parEle = parEle.parentNode;
// }
return false;
},

render部分
 {
!this.state.newDetailShow &&
<div className="new-list" ref="newListId">
<div className="swiper-container " id={ this.props.place +'NewSwiperId'} style={{transform: this.props.place == 'top' ? 'rotateZ(180deg)': 'rotateZ(0deg)'}}> <div className="swiper-wrapper">
{
this.state.newData && this.state.newData.map((item,index) => {
return (
<div className="swiper-slide" key={index} data-i={index}>
<img src={item['titlepic'].toLowerCase().indexOf("http") !== 0 ? "http://" + item['titlepic'] : item['titlepic']} style={{transform: this.props.place == 'top' ? 'rotateZ(180deg)': 'rotateZ(0deg)'}} />
<div className="swiper-mask"></div>
</div>
)
})
}
{/*onClick={this.newslistclick.bind(item,index)}*/} </div>
<div className="container" id={ this.props.place +'buttonId'} >
<div className="swiper-button-next" id={ this.props.place +'button-next'} ></div>
<div className="swiper-button-prev" id={ this.props.place +'button-prev'}></div>
</div>
</div> </div>
}

react使用swiper,解决添加点击事件首位图片点击失效,解决轮播按钮被覆盖问题的更多相关文章

  1. JS: javascript 点击事件执行两次js问题 ,解决jquery绑定click事件出现点击一次执行两次问题

    javascript 点击事件执行两次js问题 在JQuery中存在unbind()方法,先解绑再添加点击事件,解决方案为: $(".m-layout-setting").unbi ...

  2. echarts 图的点击事件(含:点击重复触发的问题及其解决方法)

    今天用echarts的时候发现一个问题 鼠标指向不同地市触发一个事件展示该地区趋势图  但是但是后台中不管我第几次鼠标指向都会触发两次指向事件 现在贴出解决办法: 问题完美解决.但是为什么会调用两次, ...

  3. Swift 导航栏设置图片点击事件,图片蓝色的解决方案

    如果导航栏想做一个点击事件,正好是一个图片 我们可以直接这样: self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIIm ...

  4. pyqt的多Button的点击事件的槽函数的区分发送signal的按钮。

    关键函数:QPushButton的setObjectName()/objectName() 个人注解:按功能或者区域,将按钮的点击事件绑定的不同的槽函数上. from PyQt5.QtWidgets ...

  5. 在CTreeCtrl控件点击事件中获取点击的项

    网上搜了一下,有两种方法: 1.使用GetSelectedItem() HTREEITEM hItem = m_treeCtrl.GetSelectedItem(); CString strText ...

  6. javascript基础1 语法 点击事件 超链接带点击事件

    javascript ----------------------------------------------------------------------------------------- ...

  7. 点击DIV触发其他元素的点击事件(案例:点击type="radio" 的input 标签外层DIV,触发内部单选点击选中事件)

    方法一: 直接用找到对应dom元素调用.click()方法 $('.user_content').click(function(){ $(this).children()[0].click(); // ...

  8. 417 事件、监听、jQuery、轮播手动

    am:通用事件 a链接事件阻止默认行为 return false HTML元素大都包含了自己的默认行为,例如:超链接.提交按钮等.我们可以通过在绑定事件中加上return false来阻止它的默认行为 ...

  9. 点击轮播图片左右button,实现轮播效果

    点击左右button.实现图片轮播效果.js代码例如以下: $(function () { var index = 1; var pPage = 1; var $v_citemss = $(" ...

随机推荐

  1. The Battle of Chibi

    The Battle of Chibi 给出一段长度为n的序列\(\{a_i\}\),求其中长度为m的严格上升子序列个数\(mod\ 10^9+7\),\(n\leq 10^3\). 解 不难想到设\ ...

  2. BeanPostProcessor原理学习

    <Spring源码解析>笔记 1.自定义的BeanPostProcessor @Component public class MyBeanPostProcessor implements ...

  3. Perl 变量

    Perl 变量 变量是存储在内存中的数据,创建一个变量即会在内存上开辟一个空间. 解释器会根据变量的类型来决定其在内存中的存储空间,因此你可以为变量分配不同的数据类型,如整型.浮点型.字符串等. 上一 ...

  4. thinkphp import标签

    传统方式的导入外部JS和CSS文件的方法是直接在模板文件使用: 直线电机哪家好 <script type='text/javascript' src='/Public/Js/Util/Array ...

  5. day 86 Vue学习之八geetest滑动验证

    Vue学习之八geetest滑动验证   本节目录 一 geetest前端web中使用 二 xxx 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 geetest前端web ...

  6. ims注册与注销

    ims注册流程: 步骤1:当IMS和SIM访问已经就绪时,IMC将在满足条件后触发IMS注册到IMCB.步骤2.3:IMCB请求IMSA/IMSM获取IMS PDN和P-CSCF,然后触发VoLTE ...

  7. Daemon 守护线程(27-11)

    t2.setDaemon(True)不再等待里面的sleep(5). 当设成setDaemon(True)这个线程就不等了. 例子一: import threadingfrom time import ...

  8. 使用virtualenv发布Python程序

    客户环境不能上网,开始想把所有依赖包下载下来,进入客户环境进行安装.但为了避免出差,部署工作交给其他同事了,我想还是需要更简单的方式. 实验了一下virtualenv是可以的 1. 创建一个新的环境( ...

  9. Office2016只安装三件套方法

    转载 Office2016只安装三件套方法(word,ppt,excel) 2019-03-01 23:30:03 Kellen5l 阅读数 11618更多 分类专栏: Office   版权声明:本 ...

  10. 使用CEfSharp之旅(2) js前台事件执行后台方法

    原文:使用CEfSharp之旅(2) js前台事件执行后台方法 版权声明:本文为博主原创文章,未经博主允许不得转载.可点击关注博主 ,不明白的进群191065815 我的群里问 https://blo ...