网站代码可以在Chrome和Firefox,台式机或移动设备上正常运行,但不能在Safari上运行

时间:2018-11-06 05:12:25

标签: javascript safari frontend mobile-safari wixcode

我的网站的某些部分在Chrome和Firefox上可以正常运行,但在Safari上似乎无法正常运行。我检查了一下,所有在iPhone上尝试该网站的人都启用了Javascript。关于我的代码,Safari是否无法读取?有没有可用的工具来测试我可以在Windows计算机上使用的Safari如何看待代码?

下面是我网站上的代码。我必须用不同的内容替换所有图像和文本,因为禁止共享实际内容。本质上,该网站的内容将允许某人通过滑杆输入某个指标,并查看该指标的外观。滑块似乎是可移动的,但是在通过Safari浏览时,图像没有出现,也没有移动。另外,我将这段代码转换为https(Wix在一个文本块中指的是全部),并将其作为html元素插入到Wix网站中。

我意识到我的JavaScript有很多冗余,例如在本地定义同一变量两次,而不是在全局定义一次。我希望稍后再解决这些问题,并首先使其正常工作(尽管这可能就是为什么它在Safari上不起作用的原因?)。我以前从未开发过任何东西,因此,不胜感激。

更新:我有几个人给我发送了屏幕截图,并且滑动条和javascript正常工作,图像只是没有显示在Safari上。

HTML

<html lang="en">

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

  </head>

  <body>

    <!-- Box-->
    <div class="wholething">
      <div class="box">
        <!-- Dude -->
        <img class="img-square img-dude" src="https://i.pinimg.com/474x/ff/5a/74/ff5a741afd59d527f4492c593b329106--free-clipart-downloads-free-clipart-images.jpg" id="dude" </img>

        <!-- Banana-->
        <img class="img-square img-bn" src=" https://upload.wikimedia.org/wikipedia/commons/0/0a/Candy-clipart.svg" id="flag">
        </img>

        <div class="whitebox" id="whiteboxID">
        </div>

        <img class="gorilla" src="https://openclipart.org/download/249534/1464300474.svg" id="gorillaID" </img>

      </div>

      <h1 class="sliderlabel" id="sliderlabelID">Hunger level</h1>
      <h1 class="sliderlabelinfo" id="sliderlabelinfoID">(drag to select)</h1>

      <!-- Slider -->
      <div class="slidecontainer">
        <input type="range" min="3" max="10" value="5" step="0.1" class="slider" id="inchslider">
        <output name="rangeVal" id="value"></output>
      </div>
    </div>
  </body>

</html>

CSS

html {
  overflow-y: hidden;
}

.wholething {
  height: 100%;
  width: 100%;
  left: 0;
  right: 0;
  margin-left: auto;
  margin-right: auto;
  position: absolute;
}

.box {
  background-color: #F5F4EF;
  height: 60%;
  width: 81.25%;
  position: absolute;
  left: 0;
  right: 0;
  margin-left: auto;
  margin-right: auto;
  border-radius: 5%;
}

.img-dude {
  position: absolute;
  top: 0;
  bottom: 0;
  margin-top: auto;
  margin-bottom: auto;
  margin-left: 20px;
  height: 90%;
}

.img-bn {
  position: absolute;
  top: 0;
  bottom: 0;
  margin-top: auto;
  margin-bottom: auto;
  z-index: 2;
  height: 10.125%;
}

.whitebox {
  position: absolute;
  background-color: #F5F4EF;
  top: 0;
  bottom: 0;
  height: calc(15% + 15px);
  width: calc(15% + 20px);
  margin-top: auto;
  margin-bottom: auto;
  z-index: 1;
}

.gorilla {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0%;
  margin-top: auto;
  margin-bottom: auto;
  z-index: 2;
  height: 90%;
  display: none;
}

.sliderlabel {
  position: absolute;
  left: 12.5%;
  top: 61%;
  font-size: 16px;
  font-family: Arial;
  font-weight: 900;
}

.sliderlabelinfo {
  position: absolute;
  left: 12.5%;
  top: 66.5%;
  font-size: 14px;
  font-family: Arial;
  font-weight: 500;
}

.slidervalue {
  position: absolute;
  top: 20px;
  left: 28.5%;
}

.slidecontainer {
  width: 75%;
  position: absolute;
  left: 0;
  right: 0;
  top: 90%;
  margin-left: auto;
  margin-right: auto;
}

.slider {
  -webkit-appearance: none;
  -moz-apperance: none;
  width: 100%;
  height: 10px;
  background-image: -webkit-gradient( linear, left top, right top, color-stop(0.15, #4BD1A0), color-stop(0.15, #F5F4EF));
  position: absolute;
  outline: none;
  opacity: 0.7;
  -webkit-transition: .2s;
  transition: opacity .2s;
  border-radius: 5px;
  left: 0;
  right: 0;
  margin-left: auto;
  margin-right: auto;
}

.slider:hover {
  opacity: 1;
  box-shadow: 0 0 0 2px #4BD1A0;
}

.slider::-webkit-slider-thumb:hover+output {
  display: block;
  transform: translateX(-50%);
  box-shadow: 0 0 0 2px #4BD1A0;
}

.slider:active {
  opacity: 1;
  box-shadow: 0 0 0 2px #4BD1A0;
}

.slider::-webkit-slider-thumb:active {
  box-shadow: 0 0 0 2px #4BD1A0;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  background: #F5F4EF;
  cursor: pointer;
  border-radius: 50%;
}

.slider::-moz-range-thumb {
  width: 25px;
  height: 25px;
  background: #4CAF50;
  cursor: pointer;
}

output {
  position: absolute;
  top: -50px;
  left: calc(28.57% + 3.25px);
  width: 80px;
  height: 30px;
  border: 1px solid #e2e2e2;
  background-color: #4BD1A0;
  border-radius: 10px;
  color: white;
  font-size: 14px;
  line-height: 30px;
  text-align: center;
  vertical-align: middle;
  display: block;
  transform: translateX(-50%);
}

input[type=range]:hover+output {
  display: block;
  transform: translateX(-50%);
}

input[type=range]:active+output {
  display: block;
  transform: translateX(-50%);
}

input[type=range] {
  background-image: -webkit-gradient(linear, left top, right top, color-stop(0.2857, #4BD1A0), color-stop(0.2857, #F5F4EF))
}

output:after {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  border-top: 10px solid #4BD1A0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  top: 100%;
  left: 40%;
  margin-top: -1px;
}

JavaScript

$(function() {
  var element = document.getElementById('dude'),
    style = window.getComputedStyle(element),
    width = style.getPropertyValue('width'),
    height = style.getPropertyValue('height');
  var slicedwidth = width.slice(0, -2);
  var slicedheight = height.slice(0, -2);
  var widthmargarin = ((Number(slicedwidth) * 0.55) + 20).toString() + "px";
  var heightmargarin = (Number(slicedheight) * 0.488).toString() + "px";
  var whiteboxwidthmargarin = ((Number(slicedwidth) * 0.55) + 25).toString() + "px";
  document.getElementById("flag").style.marginLeft = widthmargarin;
  document.getElementById("flag").style.marginBottom = heightmargarin;
  document.getElementById("value").innerHTML = "5 points";
  document.getElementById("whiteboxID").style.marginLeft = whiteboxwidthmargarin;
});

function setIcon(x, y) {
  var element = document.getElementById('dude'),
    style = window.getComputedStyle(element),
    width = style.getPropertyValue('width'),
    left = style.getPropertyValue('left'),
    height = style.getPropertyValue('height');
  var slicedwidth = width.slice(0, -2);
  var slicedheight = height.slice(0, -2);
  var widthmargarin = ((Number(slicedwidth) * 0.55) + (((x - 5) / 100 * 4.6) * Number(slicedwidth)) + 20).toString() + "px";
  var heightmargarin = ((Number(slicedheight) * 0.485) + (((y - 5) / 100 * 0.5) * Number(slicedheight))).toString() + "px";
  document.getElementById("flag").style.marginLeft = widthmargarin;
  document.getElementById("flag").style.marginBottom = heightmargarin;
  document.getElementById("flag").style.transform = "rotate(" + (7 - (x * 1.3)) + "deg)";
  document.getElementById("whiteboxID").style.marginLeft = (Number(widthmargarin.slice(0, -2)) + 5).toString() + "px";
  document.getElementById("whiteboxID").style.transform = "rotate(" + (7 - (x * 1.5)) + "deg)";
}

var slider = document.getElementById("inchslider");
var output = document.getElementById("value");
output.innerHTML = slider.value;

slider.oninput = function() {
  output.innerHTML = this.value;
  var positionXslider = 0;
  var positionYslider = 0;
  if (this.value >= 5) {
    positionXslider = output.innerHTML;
    positionYslider = output.innerHTML;
    document.getElementById("flag").src = "https://upload.wikimedia.org/wikipedia/commons/0/0a/Candy-clipart.svg";
  } else if (this.value >= 4 && this.value < 5) {
    positionXslider = 5;
    positionYslider = 5;
    document.getElementById("flag").src = "https://openclipart.org/download/284444/1502025489.svg";
  } else if (this.value < 4) {
    positionXslider = 5;
    positionYslider = 5;
    document.getElementById("flag").src = "https://image.shutterstock.com/image-vector/slice-pizza-on-white-background-260nw-597727904.jpg";
  } else {
    positionXslider = output.innerHTML;
    positionYslider = output.innerHTML;
  }
  setIcon(positionXslider, positionYslider);

};

$('input[type="range"]').on('input', function() {
  var val = ($(this).val() - $(this).attr('min')) / ($(this).attr('max') - $(this).attr('min'));

  $(this).css('background-image',
    '-webkit-gradient(linear, left top, right top, ' +
    'color-stop(' + val + ', #4BD1A0), ' +
    'color-stop(' + val + ', #F5F4EF)' +
    ')'
  );
});

$('input[type="range"]').on('input', function() {

  var control = $(this),
    controlMin = control.attr('min'),
    controlMax = control.attr('max'),
    controlVal = control.val(),
    controlThumbWidth = 25;

  var range = controlMax - controlMin;

  var position = ((controlVal - controlMin) / range) * 100;
  var positionOffset = Math.round(controlThumbWidth * position / 100) - (controlThumbWidth / 2) + 2.25;
  var output = control.next('output');
  var controlValNumber = Number(controlVal)
  var controlValLabel = 0;

  if (controlValNumber >= 5) {
    controlValLabel = controlVal.slice(0, 3);
  } else if (controlValNumber >= 4 && controlValNumber < 5) {
    controlValLabel = 4;
  } else if (controlValNumber < 4) {
    controlValLabel = 3;
  }

  if (controlValNumber >= 10) {
    document.getElementById("gorillaID").style.display = "block";
  } else {
    document.getElementById("gorillaID").style.display = "none";
  }

  output
    .css('left', 'calc(' + position + '% - ' + positionOffset + 'px)')
    .text(controlValLabel + " points")
});

0 个答案:

没有答案