781 Star 1.5K Fork 349

开源中国 / Gitee Feedback

 / 详情

图片显示问题

已完成
缺陷(Bug)
创建于  
2023-07-30 19:31

gitee上次的文件统一目录下,为什么图片js动态添加的就不显示,css引入或直接写img标签嵌入的就可以,而且资源文件打开莫名其妙的多出了tree/master这么两层是什么鬼

评论 (13)

已注销用户 创建了缺陷(Bug)

贴截图,细说。

“html 文件动态路径不显示”是什么意思?

输入图片说明这个时本地跑起来的样子

liu 添加了
 
需要更多信息
标签

为什么图片js动态添加的就不显示

怎么添加的?给个示例代码?

Factory.prototype.shufflingFigure=function(obj){
	if(obj.id=="" || obj.id==null || obj.id==undefined || !obj.id){
		return;
	};
	if(obj.Data=="" || obj.Data==null || obj.Data==undefined || !obj.Data){
		return;
	};
	var index=0,n=0;
	var type=obj.type || "cross";
	// 外层div
	var rotation=document.getElementById(obj.id);
	var MyWidth=rotation.clientWidth;
	var MyHeight=rotation.clientHeight;
	rotation.style.overflow="hidden";
	rotation.style.position="relative";
	//只有一张图片时不轮播
	if(obj.Data.length==1){
		var IMGS=document.createElement("img");
		IMGS.style.width=MyWidth+"px";
		IMGS.style.height=MyHeight+"px";
		IMGS.src=obj.Data[0].img;
		IMGS.onclick="navigateTo('"+obj.Data[0].url+"')";
		rotation.appendChild(IMGS);
		return;
	};
	//创建轮播图盒子
	var Img_Shuffling=document.createElement("ul");
	var ImgHtml="";
	if(type=="cross"){//横向轮播图
		ImgHtml+="<li style='float:left;cursor:pointer;width:"+MyWidth+"px;height:"+MyHeight+"px;list-style:none;' onclick='navigateTo(\""+obj.Data[obj.Data.length-1].url+"\",\""+obj.Data[obj.Data.length-1].target+"\")'><img src=\""+obj.Data[obj.Data.length-1].img+"\" style='width:"+(obj.Data[obj.Data.length-1].width || "auto")+";height:"+(obj.Data[obj.Data.length-1].height || "auto")+"' alt='暂无图片'/></li>";
		for(var i=0;i<obj.Data.length;i++){
			ImgHtml+="<li style='float:left;cursor:pointer;width:"+MyWidth+"px;height:"+MyHeight+"px;list-style:none;' onclick='navigateTo(\""+obj.Data[i].url+"\",\""+obj.Data[i].target+"\")'><img src=\""+obj.Data[i].img+"\" style='width:"+(obj.Data[i].width || "auto")+";height:"+(obj.Data[i].height || "auto")+"' alt='暂无图片'/></li>";
		};
		ImgHtml+="<li style='float:left;cursor:pointer;width:"+MyWidth+"px;height:"+MyHeight+"px;list-style:none;' onclick='navigateTo(\""+obj.Data[0].url+"\",\""+obj.Data[0].target+"\")'><img src=\""+obj.Data[0].img+"\" style='width:"+(obj.Data[0].width || "auto")+";height:"+(obj.Data[0].height || "auto")+"' alt='暂无图片'/></li>";
		Img_Shuffling.style.width = MyWidth * (obj.Data.length + 2) + "px";
		Img_Shuffling.style.height = MyHeight + "px";
		Img_Shuffling.style.left = "-" + MyWidth + "px";
	};
	if(type=="vertical"){
		ImgHtml+="<li style='cursor:pointer;width:"+MyWidth+"px;height:"+MyHeight+"px;list-style:none;' onclick='navigateTo(\""+obj.Data[obj.Data.length-1].url+"\",\""+obj.Data[obj.Data.length-1].target+"\")'><img src=\""+obj.Data[obj.Data.length-1].img+"\" style='width:"+(obj.Data[obj.Data.length-1].width || "auto")+";height:"+(obj.Data[obj.Data.length-1].height || "auto")+"' alt='暂无图片'/></li>";
		for(var i=0;i<obj.Data.length;i++){
			ImgHtml+="<li style='cursor:pointer;width:"+MyWidth+"px;height:"+MyHeight+"px;list-style:none;' onclick='navigateTo(\""+obj.Data[i].url+"\",\""+obj.Data[i].target+"\")'><img src=\""+obj.Data[i].img+"\" style='width:"+(obj.Data[i].width || "auto")+";height:"+(obj.Data[i].height || "auto")+"' alt='暂无图片'/></li>";
		};
		ImgHtml+="<li style='cursor:pointer;width:"+MyWidth+"px;height:"+MyHeight+"px;list-style:none;' onclick='navigateTo(\""+obj.Data[0].url+"\",\""+obj.Data[0].target+"\")'><img src=\""+obj.Data[0].img+"\" style='width:"+(obj.Data[0].width || "auto")+";height:"+(obj.Data[0].height || "auto")+"' alt='暂无图片'/></li>";
		Img_Shuffling.style.width = MyWidth  + "px";
		Img_Shuffling.style.height = MyHeight * (obj.Data.length + 2)+ "px";
		Img_Shuffling.style.top = "-" + MyHeight + "px";
	};
	
	Img_Shuffling.style.position = "absolute";
	Img_Shuffling.id = obj.id+"1";
	Img_Shuffling.style.padding = 0;
	Img_Shuffling.style.margin = 0;
	Img_Shuffling.innerHTML=ImgHtml;
	//下方带颜色的按钮
	var Ol=document.createElement("ol");
	Ol.style.position="absolute";
	if(obj.point.top){
		Ol.style.top=obj.point.top;
	};
	if(obj.point.bottom){
		Ol.style.bottom=obj.point.bottom;
	};
	if(obj.point.left){
		Ol.style.left=obj.point.left;
	};
	if(obj.point.right){
		Ol.style.right=obj.point.right;
	};
	if(!obj.point.right && !obj.point.left){
		Ol.style.left="50%";
	};
	if(!obj.point.top && !obj.point.bottom){
		Ol.style.bottom="16px";
	};
	Ol.style.transform="translateX(-50%)";
	Ol.style.zIndex="2";
	Ol.id=obj.id+"2";
	var olHtml="";
	for(var i=0;i<obj.Data.length;i++){
		olHtml+="<li style='float:left;cursor:pointer;margin-right:10px;list-style:none;width:" + Math.round(MyWidth * 0.013) + "px;height:" + Math.round(MyWidth * 0.013) + "px;background-color:"+(obj.point.default || "#ffffff")+";color:"+(obj.point.color || "#000000")+";text-align:center;line-height:" + Math.round(MyWidth * 0.013) + "px;transition:all .5s linear;"+(obj.point.shape=="square"?"":"border-radius: 50%;")+"font-size:"+(obj.point.size || "16px")+"' data='"+i+"'>"+(obj.point.font==true?(i+1):"")+"</li>";
	};
	Ol.innerHTML=olHtml;
	if(obj.point.show==true){
		Ol.style.display="block";
	}else{
		Ol.style.display="none";
	};
	//左边箭头
	var button1 = document.createElement("div");
	button1.className = "leftBtnLbt";
	button1.style.width = Math.round(MyWidth * 0.016) + "px";
	button1.style.height = Math.round(MyHeight * 0.136) + "px";
	button1.style.position = "absolute";
	button1.style.top = "50%";
	button1.style.left = "32px";
	button1.style.transform = "translateY(-50%)";
	button1.innerHTML = "&lt;";
	button1.style.backgroundColor = "rgba(190,190,190,0.5)";
	button1.style.lineHeight = Math.round(MyHeight * 0.136) + "px";
	button1.style.fontSize = Math.round(MyWidth * 0.016) + "px";
	button1.style.color = obj.point.selectedText || "#ffffff";
	button1.style.cursor = "pointer";
	button1.style.textAlign = "center";
	if(obj.arrow==true){
		button1.style.display = "block";
	}else{
		button1.style.display = "none";
	};
	if(type=="vertical"){
		button1.style.display = "none";
	};
	//右边箭头
	var button2 = document.createElement("div");
	button2.className = "rightBtnLbt";
	button2.style.width = Math.round(MyWidth * 0.016) + "px";
	button2.style.height = Math.round(MyHeight * 0.136) + "px";
	button2.style.position = "absolute";
	button2.style.top = "50%";
	button2.style.right = "32px";
	button2.style.transform = "translateY(-50%)";
	button2.innerHTML = "&gt;";
	button2.style.backgroundColor = "rgba(190,190,190,0.5)";
	button2.style.lineHeight = Math.round(MyHeight * 0.136) + "px";
	button2.style.textAlign = "center";
	button2.style.fontSize = Math.round(MyWidth * 0.016) + "px";
	button2.style.color = obj.point.selectedText || "#ffffff";
	button2.style.cursor = "pointer";
	if(obj.arrow==true){
		button2.style.display = "block";
	}else{
		button2.style.display = "none";
	};
	if(type=="vertical"){
		button2.style.display = "none";
	};
	// 在页面上展示
	rotation.appendChild(Img_Shuffling);
	rotation.appendChild(Ol);
	rotation.appendChild(button1);
	rotation.appendChild(button2);
	//处理动画
	var rotateFather=document.getElementById(obj.id+"1");
	var lis=rotateFather.children;
	var oli=document.getElementById(obj.id+"2").children;
	var leftBtn=document.getElementsByClassName("leftBtnLbt")[0];
	var rightBtn=document.getElementsByClassName("rightBtnLbt")[0];
	//下方按钮选中样式赋值
	oli[index].style.backgroundColor=obj.point.selected || "#00ff00";
	oli[index].style.color=obj.point.selectedText || "#ffffff";
	//清除下方按钮选中样式
	var clearColor = function() {
		for (var i=0; i<oli.length;i++) {
			oli[index].style.backgroundColor = obj.point.default || "#ffffff";
			oli[index].style.color=obj.point.color || "#333333";
		};
	};
	//右边点击
	rightBtn.onclick = function() {
		clearColor();
		index++;
		if (index > obj.Data.length - 1) {
			index = 0;
		};
		oli[index].style.backgroundColor=obj.point.selected || "#00ff00";
		oli[index].style.color=obj.point.selectedText || "#ffffff";
		n++;
		if(type=="vertical"){
			rotateFather.style.transform = "translateY(" + (n * -MyHeight) + "px)";
		}else{
			rotateFather.style.transform = "translateX(" + (n * -MyWidth) + "px)";
		}
		rotateFather.style.transition = "all .5s linear";
		setTimeout(function() {
			if (n >= obj.Data.length) {
				n = 0;
				if(type=="vertical"){
					rotateFather.style.transform = "translateY(0px)";
				}else{
					rotateFather.style.transform = "translateX(0px)";
				};
				rotateFather.style.transition = "all 0s linear";
			};
		}, 500);
	};
	//左边点击
	leftBtn.onclick = function() {
		clearColor();
		index--;
		if (index < 0) {
			index = obj.Data.length - 1;
		};
		oli[index].style.backgroundColor=obj.point.selected || "#00ff00";
		oli[index].style.color=obj.point.selectedText || "#ffffff";
		n--;
		if(type=="vertical"){
			rotateFather.style.transform = "translateY(" + (n * -MyHeight) + "px)";
		}else{
			rotateFather.style.transform = "translateX(" + (n * -MyWidth) + "px)";
		};
		rotateFather.style.transition = "all .5s linear";
		setTimeout(function(){
			if(n<0){
				n=obj.Data.length-1;
				if(type=="vertical"){
					rotateFather.style.transform = "translateY(" + (n * -MyHeight) + "px)";
				}else{
					rotateFather.style.transform = "translateX(" + (n * -MyWidth) + "px)";
				};
				rotateFather.style.transition = "all 0s linear";
			};
		},500)
	};
	//右边点击定时器 1s一次
	var timer = setInterval(function() {
		rightBtn.click();
	}, (obj.Time || 5000));
	//进入轮播停止定时器
	rotation.onmouseenter = function() {
		clearInterval(timer);
	};
	//离开轮播开启定时器
	rotation.onmouseleave = function() {
		timer = setInterval(function() {
			rightBtn.click();
		}, (obj.Time || 5000));
	};
	//移动下面的小li显示对于的图片
	for (var i = 0; i < oli.length; i++) {
		oli[i].onmouseenter=function(){
			oli[index].style.backgroundColor = obj.point.default || "#ffffff";
			oli[index].style.color = obj.point.color || "#000000";
			this.style.backgroundColor=obj.point.selected || "#00ff00";
			this.style.color=obj.point.selectedText || "#ffffff";
			index=Number(this.getAttribute("data"));
			n=index;
			if(type=="vertical"){
				rotateFather.style.transform = "translateY(" + (n * -MyHeight) + "px)";
			}else{
				rotateFather.style.transform = "translateX(" + (n * -MyWidth) + "px)";
			};
			rotateFather.style.transition = "all 0.5s linear";
			setTimeout(function() {
				if (n >= obj.Data.length) {
					n = 0;
					if(type=="vertical"){
						rotateFather.style.transform = "translateY(0px)";
					}else{
						rotateFather.style.transform = "translateX(0px)";
					};
					rotateFather.style.transition = "all 0s linear";
				};
			}, 500);
		};
	};
};

封装的轮播图

Query.shufflingFigure({
		id:"CarouselMap",
		type:"cross",
		Data:[{
			img:"./Resource/imgs/index/banner-1.jpg",
			url:"",
			width:"100%"
		},{
			img:"./Resource/imgs/index/banner-2.jpg",
			url:"",
			width:"100%"
		},{
			img:"./Resource/imgs/index/banner-3.jpg",
			url:"",
			width:"100%"
		},{
			img:"./Resource/imgs/index/banner-4.jpg",
			url:"",
			width:"100%"
		}],
		Time:12000,
		point:{
			show:false
		}
	});

这个是通过JS去创建的轮播图
而且本地运行时可以访问到的,但是gitpage上传上去就是访问不到

代码部署到 Pages 服务上后访问不到图片?
建议检查页面路径、JS 请求的图片路径、图片文件的实际路径。

输入图片说明是的,部署上去就没有图片了

而且我在控制台看了,地址时和本地运行的一样的

568 lc soft 1586692424 头像挂件 liu 成员
回复 liu 成员

本地能访问,是因为你的 Windows 系统对大小写不敏感,路径里的 Index 和 index 都能访问同一个文件。

建议文件名和路径都用小写。

好的,谢谢

你的路径写错了,/Index/ 里的 i 是大写 I,你用了小写 i

http://http_wang-sx.gitee.io/pc/Resource/imgs/index/banner-1.jpg
http://http_wang-sx.gitee.io/pc/Resource/imgs/Index/banner-1.jpg

你对比其它能正常加载的图片的路径就能发现区别,例如:

http://http_wang-sx.gitee.io/pc/Resource/imgs/Index/new.jpeg

里面的 Index 就是大写 I

liu 任务状态待确认 修改为已完成

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
568 lc soft 1586692424 Avatar default
Ruby
1
https://gitee.com/oschina/git-osc.git
git@gitee.com:oschina/git-osc.git
oschina
git-osc
Gitee Feedback

搜索帮助

344bd9b3 5694891 D2dac590 5694891