Flip Horizontal CSS and reverse it with JavaScript based on RTL Direction

纵然是瞬间 提交于 2019-12-02 02:06:32

It works when i force body to show either dir=rtl or dir=ltr. And for flip, i use your css and put * as the selector too select all element. check this out:

var b = document.getElementsByTagName("body")[0];
b.setAttribute("dir", "rtl");
/* b.setAttribute("dir", "ltr"); */
console.log(b);
<h1> Hello world </h1>
<div> Text Here</div>
<p>lorem ipsum lorem ipsum lorem ipsum</p>

More about this: Css Tricks on text direction

in case you want to flip all element can add this:

* {
-moz-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
-o-transform: scaleX(-1);
transform: scaleX(-1);
-ms-filter: fliph; /*IE*/
filter: fliph; /*IE*/
}

But if you means: from Hello world you want it to appear as dlrow olleH you can try this one:

var ns = document.body.childNodes;
ns.forEach(function(elm) {
  if (elm.innerText && elm.nodeName !== "SCRIPT") {
    //set array of char then re-arrange char
    var arr = elm.innerText.split(''),
      temp = [];
    for (var i = 0, l = x = arr.length - 1; i <= l; i++, x--) {
      temp[i] = arr[x];
    }
    elm.innerText = temp.join('')
  }
})
<h1> Hello world </h1>
<div>Text Here</div>
<p>lorem ipsum<span> span </span>lorem ipsum lorem ipsum</p>

As you are using flipH filter.

$(document).on("click","html",function(){
  $(this).toggleClass("flipX");
})
body {
  background-image: linear-gradient(to left, rebeccapurple, skyblue);
  color: white;
}

.flipX {
  -webkit-transform: scaleX(-1);
          transform: scaleX(-1);
  -ms-filter: "FlipH";
  -webkit-filter: FlipH;
          filter: FlipH;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<h1>Page Title</h1>
<p>Click to flip...</p>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!